{"action":"created","issue":{"url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/3","repository_url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling","labels_url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/3/comments","events_url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/3/events","html_url":"https://github.com/cta-sst-1m/digicamscheduling/issues/3","id":348460637,"node_id":"MDU6SXNzdWUzNDg0NjA2Mzc=","number":3,"title":"different default values for `start_date` and `end_date`","user":{"login":"dneise","id":8200858,"node_id":"MDQ6VXNlcjgyMDA4NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/8200858?v=4","gravatar_id":"","url":"https://api.github.com/users/dneise","html_url":"https://github.com/dneise","followers_url":"https://api.github.com/users/dneise/followers","following_url":"https://api.github.com/users/dneise/following{/other_user}","gists_url":"https://api.github.com/users/dneise/gists{/gist_id}","starred_url":"https://api.github.com/users/dneise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dneise/subscriptions","organizations_url":"https://api.github.com/users/dneise/orgs","repos_url":"https://api.github.com/users/dneise/repos","events_url":"https://api.github.com/users/dneise/events{/privacy}","received_events_url":"https://api.github.com/users/dneise/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-08-07T19:43:08Z","updated_at":"2018-08-14T07:39:11Z","closed_at":null,"author_association":"NONE","body":"I think it might be useful for some of the scripts to use different defaults for `start_date` and `end_date`:\r\nI would say: \r\n\r\nIf one is using the scripts at some time after dawn, then one most probably wants to know the schedule for the next night. \r\n\r\nIf one is using the scripts after sun set, then one most probably wants to know something about the current night. Maybe one wants to cross check something or so. \r\n\r\nWhat do you think, should we implement that?"},"comment":{"url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/comments/412782808","html_url":"https://github.com/cta-sst-1m/digicamscheduling/issues/3#issuecomment-412782808","issue_url":"https://api.github.com/repos/cta-sst-1m/digicamscheduling/issues/3","id":412782808,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjc4MjgwOA==","user":{"login":"dneise","id":8200858,"node_id":"MDQ6VXNlcjgyMDA4NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/8200858?v=4","gravatar_id":"","url":"https://api.github.com/users/dneise","html_url":"https://github.com/dneise","followers_url":"https://api.github.com/users/dneise/followers","following_url":"https://api.github.com/users/dneise/following{/other_user}","gists_url":"https://api.github.com/users/dneise/gists{/gist_id}","starred_url":"https://api.github.com/users/dneise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dneise/subscriptions","organizations_url":"https://api.github.com/users/dneise/orgs","repos_url":"https://api.github.com/users/dneise/repos","events_url":"https://api.github.com/users/dneise/events{/privacy}","received_events_url":"https://api.github.com/users/dneise/received_events","type":"User","site_admin":false},"created_at":"2018-08-14T07:39:11Z","updated_at":"2018-08-14T07:39:11Z","author_association":"NONE","body":"Okay, cool so we agree some other defaults could be possible.\r\nI would take a different approach (result might be the same ... depends on definition of \"today\", I think)\r\n\r\n```python\r\nimport ephem\r\nimport numpy as np\r\nfrom datetime import datetime, timedelta\r\n\r\nSun = ephem.Sun()\r\n\r\nkrakow = ephem.Observer()\r\nkrakow.lon = '19:56:15.234'  # Location just estimated from google maps\r\nkrakow.lat = '50:03:42.196'  # Exact location to be put here\r\nkrakow.elevation = 200       # Exact height to be put here\r\nkrakow.horizon = np.deg2rad(-18)  # astro twilight is defined between -12° and -18°\r\n\r\n\r\ndef next_astro_dusk(after):\r\n    krakow.date = after\r\n    astro_dusk = krakow.next_setting(Sun).datetime()\r\n    return astro_dusk\r\n\r\n\r\ndef next_astro_dawn(after):\r\n    krakow.date = after\r\n    astro_dawn = krakow.next_rising(Sun).datetime()\r\n    return astro_dawn\r\n\r\n\r\ndef is_during_day(current_time):\r\n    next_dusk = next_astro_dusk(after=current_time)\r\n    next_dawn = next_astro_dawn(after=current_time)\r\n\r\n    is_during_day = next_dusk - current_time < next_dawn - current_time\r\n    return is_during_day\r\n\r\n\r\ndef calculate_defaults(current_time=datetime.utcnow()):\r\n    '''\r\n    We say a good default start_time and end_time depends on whether we are\r\n    currently \"during day\" or \"in the middle of the night\". Since we assume a\r\n    human executing this program during the day, wants to know something about\r\n    the next night, while a human executing this during the night, wants to\r\n    review the plan for the current night and not necessarily plan for the\r\n    next night.\r\n    '''\r\n\r\n    if is_during_day(current_time):\r\n        # start_time is the next dusk\r\n        start_time = next_astro_dusk(after=current_time)\r\n        end_time = next_astro_dawn(after=current_time)\r\n    else:  # is_during_night\r\n        start_time = next_astro_dusk(after=current_time - timedelta(days=1))\r\n        end_time = next_astro_dawn(after=current_time)\r\n\r\n    return dict(\r\n        start_time=start_time,\r\n        end_time=end_time\r\n    )\r\n\r\n\r\ndef times_are_close(dt1, dt2, epsilon=2):\r\n    ''' For this test we are fine with 2sec discrepancy.\r\n    '''\r\n    return (dt2 - dt1).total_seconds() < epsilon\r\n\r\n\r\ndef test_during_daytime():\r\n    current_time = datetime(2018, 8, 14, 12, 00, 00)\r\n    defaults = calculate_defaults(current_time)\r\n    start_time = defaults['start_time']\r\n    end_time = defaults['end_time']\r\n\r\n    # start_time should be in the *next* evening\r\n    # end_time should be in the *next morning\r\n    assert times_are_close(start_time, datetime(2018, 8, 14, 20, 19, 21))\r\n    assert times_are_close(end_time, datetime(2018, 8, 15, 1, 10, 55))\r\n\r\n\r\ndef test_during_shift():\r\n    #\r\n    current_time = datetime(2018, 8, 14, 23, 59, 00)\r\n    defaults = calculate_defaults(current_time)\r\n    start_time = defaults['start_time']\r\n    end_time = defaults['end_time']\r\n\r\n    # start_time should be the *previous* evening, just some hours ago\r\n    # end_time should be in the *next* morning, in a few hours\r\n    assert times_are_close(start_time, datetime(2018, 8, 14, 20, 19, 21))\r\n    assert times_are_close(end_time, datetime(2018, 8, 15, 1, 10, 55))\r\n```"}}
{"actor":{"display_login":"dneise"}}