示例#1
0
def test_merge_mutator_tweets(tweets):
    t1, t2, t3 = map(Tweet, tweets)

    result = []
    sink = to_list(result)
    start = DT(2000, 1, 1, 0, 0, 0)

    def mutator(i, f):
        delta = i.orig_created_at - f.orig_created_at
        i.created_at = start + delta
        return i

    def S(source):
        return lambda target: consume_iterable(
            consumers.mutate(
                target,
                mutator=mutator,
            ),
            source,
        )

    pipes = (S([t1, t2]), sink), (S([t3]), sink)
    merge(
        pipes,
        provider=lambda current: current.created_at,
    )

    assert result == [t1, t3, t2]
    assert [t.created_at for t in result] == [
        DT(2000, 1, 1, 0, 0),
        DT(2000, 1, 1, 0, 0),
        DT(2000, 1, 13, 17, 40, 37),
    ]
示例#2
0
    def test_spot_checks(self):
        # Spot checks
        from_time = DT(
            200, 2, 2, 0, 12, 12, 0,
            None)  # 12 minutes, 12 seconds past midnight on Feb 2 200AD
        to_time = DT(1981, 3, 31, 7, 31, 0, 0, None)  # 7:31 am, March 31, 1981
        assert dtw(
            from_time, to_time
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days, 7 hours, 18 minutes and 48 seconds"
        assert dtw(
            from_time, to_time, granularity="hour"
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
        assert dtw(
            from_time, to_time, granularity="hour", round=True
        ) == "17 centuries, 8 decades, 1 year, 1 month, 29 days and 7 hours"
        assert dtw(from_time, to_time, granularity="month"
                   ) == "17 centuries, 8 decades, 1 year and 1 month"
        assert dtw(
            from_time, to_time, granularity="month",
            round=True) == "17 centuries, 8 decades, 1 year and 2 months"

        from_time = DT(200, 2, 2, 12, 30, 30, 0,
                       None)  # 12:30:30, Feb 2, 200AD
        to_time = DT(220, 3, 2, 12, 30, 31, 0, None)  # 12:30:31, Mar 2, 220AD
        assert dtw(from_time, to_time) == "2 decades, 1 month and 1 second"
 def __init__(self, hicoPtr, **kwargs):
     filterwarnings('error', category=UserWarning)
     gps_time = DT(1980, 1, 6, 0, 0, 0)
     sec_per_count = 1.117460459e-6
     secOffset = TDel(seconds=15)
     self.__subSeconds2Seconds = 16.72e-6
     self.__timeWrapAround = 65536
     self.__time0Factor = 0.05
     self.__time1Factor = 62.5e-9
     do_nav_time_correction = kwargs.pop('doNavTimeCorrection', False)
     self.beginTime = DT.now()
     self.paramsDict = {}
     self.paramsDict['d_tisspvq'] = kwargs.pop('delta_tisspvq', 0)
     self.paramsDict['d_ticugps'] = kwargs.pop('delta_ticugps', 0)
     self.paramsDict['orientation'] = hicoPtr.params['issOrientation']
     self.paramsDict['gps_secs_090101'] = (DT(2009, 1, 1, 0, 0, 0) +
                                           secOffset -
                                           gps_time).total_seconds()
     self.paramsDict['trigger_pulse_width'] = 0.860e-3
     self.paramsDict['start_date_time'] = ConvLst2DT(
         hicoPtr.L0.data['start_date'], hicoPtr.L0.data['start_time'])
     self.paramsDict['end_date_time'] = ConvLst2DT(
         hicoPtr.L0.data['end_date'], hicoPtr.L0.data['end_time'])
     self.paramsDict['start_date_time'] -= secOffset
     self.paramsDict['end_date_time'] += secOffset
     self.paramsDict['thetas'] = hicoPtr.L0.data['ScenePointingAngle']
     self.paramsDict['nls'] = hicoPtr.L0.data['n_image']
     ffpps_all = hicoPtr.L0.header['FFpps'] +\
         hicoPtr.L0.header['FFppsSub'] * self.__subSeconds2Seconds
     lfpps_all = hicoPtr.L0.header['LFpps'] +\
         hicoPtr.L0.header['LFppsSub'] * self.__subSeconds2Seconds
     if ffpps_all > lfpps_all:
         ffpps_all += self.__timeWrapAround
     self.paramsDict['ffpps_all'] = ffpps_all
     self.paramsDict['lfpps_all'] = lfpps_all
     self.paramsDict[
         'exptimes'] = hicoPtr.L0.header['TriggerCount'] * sec_per_count
     self.paramsDict['odrc_time_offset'] = self.__GetODRCTimeOffset(
         hicoPtr.inpDict['hdrFile'])
     self.paramsDict['nav_time_offset'] = 0
     self.paramsDict['jday_end'] = Time(self.paramsDict['end_date_time']).jd
     self.paramsDict['jday_start'] = Time(
         self.paramsDict['start_date_time']).jd
     self.paramsDict[
         'exptimes'] = hicoPtr.L0.header['TriggerCount'] * sec_per_count
     self.paramsDict['cexp'] = '_expDEF'
     rootName = os.path.basename(hicoPtr.inpDict['l0File']).split('.bil')[0]
     self.paramsDict['pvqFileName'] = kwargs.pop(
         'outputFileName', '%s_pos_vel_quat.csv' % rootName)
     self.paramsDict['anglFileName'] = '%s_LonLatViewAngles.bil' % rootName
     self.paramsDict['csvName'] = hicoPtr.inpDict['csvFile']
     self.paramsDict['n_pixels'] = hicoPtr.L0.data['ns']
     self.__ReadCSVFile()
     if do_nav_time_correction:
         self.__GetNavOffsetTimeCorrection(rootName)
     self.__FillPoVeQuDF()
     self.finishTime = DT.now()
     self.__WriteHeader2CSV()
     self.__WriteData2CSV()
示例#4
0
 def test_datetime_duration_ops(self):
     self.assertEqual(
         compute_from_string('2015/07/31 + 1 day').datetime, DT(2015, 8, 1))
     self.assertEqual(
         compute_from_string('2015/07/31 + 2 days').datetime,
         DT(2015, 8, 2))
     self.assertEqual(
         compute_from_string('2015/02/28 + 1 day').datetime, DT(2015, 3, 1))
     self.assertEqual(
         compute_from_string('2015/05/04 + 3 hours, 10 seconds').datetime,
         DT(2015, 5, 4, 3, 0, 10))
     self.assertEqual(
         compute_from_string('2015/05/04 + 3 hours + 10 seconds').datetime,
         DT(2015, 5, 4, 3, 0, 10))
     self.assertEqual(
         compute_from_string(
             '2015/05/04 10:45 + 3 hours + 10 seconds').datetime,
         DT(2015, 5, 4, 13, 45, 10))
     self.assertEqual(
         compute_from_string(
             '2015/05/04 10:45 - 3 hours + 10 seconds').datetime,
         DT(2015, 5, 4, 7, 45, 10))
     self.assertEqual(
         compute_from_string('2015/01/31 + 2 months').datetime,
         DT(2015, 3, 31))
     self.assertEqual(
         compute_from_string('2015/04/29 + 2 months').datetime,
         DT(2015, 6, 29))
示例#5
0
def episode(mocker):

    ep = mocker.MagicMock(spec=Episode)
    ep.TYPE = 'episode'
    ep.name = ''
    ep.title = ''
    ep.grandparentTitle = 'Dexter'
    ep.ratingKey = 1337
    ep._server = ''
    ep.title = 'Dexter'
    ep.index = 1
    ep.parentIndex = 1
    ep.grandparentRatingKey = 1337
    ep.grandparentTheme = ''
    ep.duration = 60 * 60 * 1000  # 1h in ms
    ep.updatedAt = DT(1970, 1, 1)

    def _prettyfilename():
        return 'Dexter.s01.e01'

    def iterParts():
        yield os.path.join(TEST_DATA, 'dexter_s03e01_intro.mkv')

    ep._prettyfilename = _prettyfilename

    return ep
示例#6
0
def populate_full_water_temperature(request):
    obj = SoapCalls()
    DataFormat = 'json'
    sensors = obj.GetSensors(DataFormat)

    sDate = DT(2016, 1, 1)
    eDate = sDate + datetime.timedelta(days=9)
    stationNumbers = get_station_num(sensors, 'WT')

    temperature_data = None
    count = 0

    while eDate < DT.today():
        count = count + 1
        print("**** Writing batch: %s" % count)
        sDate = eDate + datetime.timedelta(days=1)
        eDate = eDate + datetime.timedelta(days=10)
        for x in stationNumbers:
            temperature_x = obj.GetTimeSeriesData(x, ['WT'], sDate.isoformat(),
                                                  eDate.isoformat(),
                                                  DataFormat)
            for x in temperature_x['TimeSeriesData']:
                wt_datetime = DT.strptime(x['TimeStamp'],
                                          '%m/%d/%Y %I:%M:%S %p')
                try:
                    wt = WT(station_id=x['StationID'],
                            station_name=x['StationName'],
                            timestamp=wt_datetime,
                            value=x['Value'])
                    wt.save()
                except Exception:
                    continue

    return HttpResponse('Written to database FULL')
示例#7
0
def populate_full_discharge(request):
    obj = SoapCalls()
    DataFormat = 'json'

    sDate = DT(2016, 1, 1)

    temperature_data = None
    count = 0

    data = np.random.uniform(0, 4, 115)
    data = np.around(data, 1)
    data = data.tolist()

    i = -1
    while sDate < DT.today():
        count = count + 1
        print("**** Writing discharge batch: %s" % count)
        i = i + 1
        date = sDate
        sDate = sDate + datetime.timedelta(days=1)
        print i
        vel = (0.2692 * data[i]) + 0.0984
        try:
            dObj = DD(station_id='HY040',
                      station_name='KROSNO CR',
                      timestamp=date,
                      value=data[i],
                      velocity=vel)
            dObj.save()
        except Exception:
            continue
    return HttpResponse('Written to discharge database FULL')
示例#8
0
    def show(self, dt_val, timezone=True):
        if not dt_val:
            self.entry.clear()
        else:
            date = time.strptime(dt_val[:8], HM_FORMAT)
            if rpc.session.context.get('tz', False) and timezone:
                try:
                    lzone = pytz.timezone(rpc.session.context['tz'])
                    szone = pytz.timezone(rpc.session.timezone)
                    dt = DT(date[0], date[1], date[2], date[3], date[4],
                            date[5], date[6])
                    sdt = szone.localize(dt, is_dst=True)
                    ldt = sdt.astimezone(lzone)
                    date = ldt.timetuple()
                except pytz.UnknownTimeZoneError:
                    # Timezones are sometimes invalid under Windows
                    # and hard to figure out, so as a low-risk fix
                    # in stable branch we will simply ignore the
                    # exception and consider client in server TZ
                    # (and sorry about the code duplication as well,
                    # this is fixed properly in trunk)
                    pass

            t = time.strftime(self.format, date)
            if len(t) > self.entry.get_width_chars():
                self.entry.set_width_chars(len(t))
            self.entry.set_text(t)
        return True
示例#9
0
    def cal_open(self, widget, event, model=None, window=None):
        if self.readonly:
            common.message(_('This widget is readonly !'))
            return True

        win = gtk.Dialog(_('OpenERP - Date selection'), window,
                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                         (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK,
                          gtk.RESPONSE_OK))

        hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_('Hour:')), expand=False, fill=False)
        hour = gtk.SpinButton(gtk.Adjustment(0, 0, 23, 1, 5), 1, 0)
        hbox.pack_start(hour, expand=True, fill=True)
        hbox.pack_start(gtk.Label(_('Minute:')), expand=False, fill=False)
        minute = gtk.SpinButton(gtk.Adjustment(0, 0, 59, 1, 10), 1, 0)
        hbox.pack_start(minute, expand=True, fill=True)
        win.vbox.pack_start(hbox, expand=False, fill=True)

        cal = gtk.Calendar()
        cal.display_options(gtk.CALENDAR_SHOW_HEADING
                            | gtk.CALENDAR_SHOW_DAY_NAMES
                            | gtk.CALENDAR_SHOW_WEEK_NUMBERS)
        cal.connect('day-selected-double-click',
                    lambda *x: win.response(gtk.RESPONSE_OK))
        win.vbox.pack_start(cal, expand=True, fill=True)
        win.show_all()

        try:
            val = self.get_value(model, timezone=False)
            if val:
                hour.set_value(int(val[11:13]))
                minute.set_value(int(val[-5:-3]))
                cal.select_month(int(val[5:7]) - 1, int(val[0:4]))
                cal.select_day(int(val[8:10]))
            else:
                hour.set_value(time.localtime()[3])
                minute.set_value(time.localtime()[4])
        except ValueError:
            pass
        response = win.run()
        if response == gtk.RESPONSE_OK:
            hr = int(hour.get_value())
            mi = int(minute.get_value())
            dt = cal.get_date()
            month = int(dt[1]) + 1
            day = int(dt[2])
            date = DT(dt[0], month, day, hr, mi)
            try:
                value = date.strftime(DHM_FORMAT)
            except ValueError:
                common.message(
                    _('Invalid datetime value! Year must be greater than 1899 !'
                      ))
            else:
                self.show(value, timezone=False)

        self._focus_out()
        win.destroy()
示例#10
0
    def _get_datetime_from_key(self, key):

        (date_str, time_str) = key.split('_')[1].split('-')
        (year, month,
         day) = [int(date_str[2 * i:2 * (i + 1)]) for i in range(3)]
        year += 2000
        (hour, minute,
         second) = [int(time_str[2 * i:2 * (i + 1)]) for i in range(3)]
        dt = DT(year, month, day, hour, minute, second)

        return dt
示例#11
0
 def __SetPeriods(self):
     '''Formatting time for writing to nc file'''
     datefmt = '%Y%m%d'
     timefmt = '%H%M%S'
     gnc_epoch = DT(1980, 1, 6)
     start_delta = TDel(0, self.L0.header['FFgncSec'])
     end_delta = TDel(0, self.L0.header['LFgncSec'])
     firstFrameDT = start_delta + gnc_epoch
     lastFrameDT = end_delta + gnc_epoch
     self.params['begin_date'] = DT.strftime(firstFrameDT, datefmt)
     self.params['end_date'] = DT.strftime(lastFrameDT, datefmt)
     self.params['begin_time'] = DT.strftime(firstFrameDT, timefmt)
     self.params['end_time'] = DT.strftime(lastFrameDT, timefmt)
示例#12
0
class TestFormerDocTests(object):
    start = DT(2008, 3, 21, 16, 34)
    end = DT(2008, 2, 6, 9, 45)

    def test1(self):
        assert dtw(86399, round=True, granularity="day") == "1 day"

    def test2(self):
        assert dtw(86399, granularity='day') == "less than 1 day"

    def test3(self):
        assert dtw(86399) == "23 hours, 59 minutes and 59 seconds"

    def test4(self):
        b = "1 month, 15 days, 6 hours and 49 minutes"
        assert dtw(self.start, self.end) == b

    def test5(self):
        b = "less than 1 decade"
        assert dtw(self.start, self.end, granularity="decade") == b

    def test6(self):
        b = "1 month, 15 days, 6 hours and 49 minutes"
        assert dtw(self.start, self.end, granularity="second") == b
示例#13
0
def bus_stops(bus):
    w_hnd = urlopen(web_site % bus)
    xml_text = w_hnd.readlines()
    root = ET.fromstring(''.join(xml_text))

    for direction in root:
        for trip in direction:
            for stop in trip[4]:

                temp_time = stop[3].text.split('T')[1].split(':')
                stop_time = DT(2013, 7, 3, int(temp_time[0]), \
                    int(temp_time[1]), int(temp_time[2]))

                if start_1 <= stop_time <= stop_1 or \
                start_2 <= stop_time <= stop_2:
                    stop_ids.append((bus, stop[0].text, stop[1].text, \
                                     stop_time))
示例#14
0
    def cal_open(self, widget, event, model=None, window=None):
        if self.readonly:
            common.message(_('This widget is readonly !'))
            return True

        if not window:
            window = service.LocalService('gui.main').window

        win = gtk.Dialog(_('OpenERP - Date selection'), window,
                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                         (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK,
                          gtk.RESPONSE_OK))
        win.set_icon(common.OPENERP_ICON)

        cal = gtk.Calendar()
        cal.display_options(gtk.CALENDAR_SHOW_HEADING
                            | gtk.CALENDAR_SHOW_DAY_NAMES
                            | gtk.CALENDAR_SHOW_WEEK_NUMBERS)
        cal.connect('day-selected-double-click',
                    lambda *x: win.response(gtk.RESPONSE_OK))
        win.vbox.pack_start(cal, expand=True, fill=True)
        win.show_all()

        try:
            val = self.get_value(model)
            if val:
                cal.select_month(int(val[5:7]) - 1, int(val[0:4]))
                cal.select_day(int(val[8:10]))
        except ValueError:
            pass

        response = win.run()
        if response == gtk.RESPONSE_OK:
            year, month, day = cal.get_date()
            dt = DT(year, month + 1, day)
            try:
                value = dt.strftime(LDFMT)
            except ValueError:
                common.message(
                    _('Invalid date value! Year must be greater than 1899 !'))
            else:
                self.entry.set_text(value)
        self._focus_out()
        window.present()
        win.destroy()
示例#15
0
    def _get_time_difference(self, key):

        (date_str, time_str) = key.split('_')[1].split('-')
        (year, month,
         day) = [int(date_str[2 * i:2 * (i + 1)]) for i in range(3)]
        (hour, minute,
         second) = [int(time_str[2 * i:2 * (i + 1)]) for i in range(3)]
        dt = DT(year, month, day, hour, minute, second)
        uts = (dt - DT.utcfromtimestamp(0)).total_seconds()
        time_diff = 0

        if self.current_time is None:
            self.current_time = uts
        else:
            time_diff = uts - self.current_time
            self.current_time += time_diff

        return time_diff
示例#16
0
 def plotRawUserTimeLine(self):
     fn = '{}{}/rawtime_{}.png'.format(FPATH,self.ref,self.ref)
     b = {}
     lgd = ()
     zero = DT(2000,1,1)
     for j,sequence in enumerate(self.res):
         minseq = min(sequence[2])
         lgd += (self._legend(j,sequence),)
         X = [i[1] for i in sequence[2]]
         #Y = [MDT.date2num(zero+(v[2]-minseq[2])) for v in sequence[2]]
         Y = [zero+(v[2]-minseq[2]) for v in sequence[2]]
         #xy = [(x,y) for x,y in zip(X,Y)]
         b[i] = PP.plot(self.offsetX(X),Y)#,color=self.colours[i])
     PP.legend(([b[bi][0] for bi in b]),lgd,loc=2)
     PP.title('Raw Zoom Timing / Res({}), User({}{})'.format(WHstr,USERS,'p' if PARA else 's'))
     PP.xlabel('zoom level')
     PP.ylabel('time (h:m:s)')
     self._output(PP,fn)
     self.fig.clear()
示例#17
0
def film(mocker):
    ep = mocker.MagicMock(spec=Movie)
    ep.TYPE = 'movie'
    ep.name = 'Random'
    ep.title = 'Random'
    ep.ratingKey = 7331
    ep._server = ''
    ep.duration = 60 * 60 * 1000  # 1h in ms
    ep.updatedAt = DT(1970, 1, 1)

    def _prettyfilename():
        return 'Random'

    p = mocker.MagicMock(spec=MediaPart)
    p.file = os.path.join(TEST_DATA, 'dexter_s03e01_intro.mkv')

    def _iterParts():
        yield p

    ep._prettyfilename = _prettyfilename
    ep.iterParts = _iterParts

    return ep
示例#18
0
 def test_sort_dates(self):
     '''test the sort_date_start/end values'''
     doc = json.load(open(DIR_FIXTURES + '/couchdb_doc.json'))
     sdoc = map_couch_to_solr_doc(doc)
     self.assertEqual(sdoc['sort_date_start'], DT(1885, 1, 1, tzinfo=UTC))
     self.assertEqual(sdoc['sort_date_end'], DT(1890, 1, 1, tzinfo=UTC))
     doc = json.load(open(DIR_FIXTURES + '/couchdb_no_pretty_id.json'))
     sdoc = map_couch_to_solr_doc(doc)
     self.assertEqual(sdoc['sort_date_start'], DT(2013, 9, 30, tzinfo=UTC))
     self.assertEqual(sdoc['sort_date_end'], DT(2013, 9, 30, tzinfo=UTC))
     doc = json.load(open(DIR_FIXTURES + '/couchdb_nocampus.json'))
     sdoc = map_couch_to_solr_doc(doc)
     self.assertNotIn('sort_date_start', sdoc)
     self.assertNotIn('sort_date_end', sdoc)
     doc = json.load(open(DIR_FIXTURES + '/couchdb_solr_date_map.json'))
     sdoc = map_couch_to_solr_doc(doc)
     self.assertEqual(sdoc['sort_date_start'], DT(1885, 7, 4, tzinfo=UTC))
     self.assertEqual(sdoc['sort_date_end'], DT(1890, 8, 3, tzinfo=UTC))
示例#19
0
 def __SetL02L1BParams(self):
     """
     Populates L02L1BParams hash (as a dict).
     In hico_L0_to_L1B_h5.bash this is equivalent to
         * filling out {basename}.raw_param
     """
     offset = -300
     ff_time = DT(
         self.L0.header['FFyearMSB'] * 100 + self.L0.header['FFyearLSB'],
         self.L0.header['FFmonth'], self.L0.header['FFday'],
         self.L0.header['FFhours'], self.L0.header['FFmin'],
         self.L0.header['FFsec'])
     timestamp = cal.timegm(ff_time.timetuple())
     dark_time = DT.utcfromtimestamp(timestamp + offset)
     ff_temp = self.__GetCamTemp(self.inpDict["csvFile"], ff_time)
     dark_temp = self.__GetCamTemp(self.inpDict["csvFile"], dark_time)
     self.params['base_dir'] = "./"
     self.params['input_dir'] = "./"
     self.params['output_dir'] = "./"
     self.params['dark_temp'] = dark_temp
     self.params['ffTemp'] = ff_temp
     self.params['flip_cal'] = True
     self.params['cal_mult'] = 1.32
     self.params['cal_shift'] = 0
     self.params['outputInterleave'] = "bil"
     self.params['outputScaleFactor'] = 50  # out_scale
     self.params['frameTransferTime'] = 0.00111
     self.params['exposureTime'] = 0.0137
     self.params['validL0Pixels'] = 508
     self.params['nb_read'] = 128  # nb
     self.params['nb_all'] = 170  # nbb
     self.params['ns'] = 512
     self.params['nl_predark'] = 200
     self.params['nl_postdark'] = 200
     self.params['out_type'] = 'uint16'
     self.__MakeFWHM()
示例#20
0
def test_merge_tweets(tweets):
    a = tweets[:1] * 3
    b = tweets[1:2] * 4
    result = []
    sink = to_list(result)

    def S(source):
        t = lambda target: consume_iterable(consumers.to_tweet(target), source)

        return t

    pipes = (S(a), sink), (S(b), sink)
    merge(pipes, provider=lambda current: current.created_at)

    assert [t.created_at for t in result] == [
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
    ]
 def GetDateTime(row):
     row = row.astype(int)
     year = row['ISSTIMECENTURY'] * 100 + row['ISSTIMEYEAR']
     return DT(year, row['ISSTIMEMONTH'], row['ISSTIMEDAY'],
               row['ISSTIMEHOUR'], row['ISSTIMEMINUTE'],
               row['ISSTIMESECOND'])
示例#22
0
from urllib import urlopen
from datetime import datetime as DT
import xml.etree.ElementTree as ET

# Constants

web_site = "http://api.wmata.com/Bus.svc/RouteSchedule?routeId=%s&date=2013-07-05&includingVariations=true&api_key=z3k93zgdm7t5cyaf7n4b72b7"
bus_list = ['11Y', '13F', '13G', '16X', '16Y', '31', '32', '34', '36', '37', \
            '38B', '39', '3Y', '42', '43', '52', '53', '54', '5A', '63', \
            '64', '70', '74 NOR', '74 SOU', '79', '7Y', '80', '96', 'A11', \
            'A42', 'A46', 'A48', 'A9', 'D1', 'D3', 'D4', 'D5', 'D6', 'D8', \
            'G8', 'H1', 'L1', 'L2', 'N2', 'N3', 'N4', 'N6', 'P17', 'P19', \
            'P6', 'S1', 'S2', 'S4', 'S9', 'V5', 'V7', 'V8', 'V9', 'W13', 'X1', \
            'X2', 'X9']

start_1 = DT(2013, 7, 3, 7, 0, 0)
stop_1 = DT(2013, 7, 3, 9, 30, 0)
start_2 = DT(2013, 7, 3, 16, 0, 0)
stop_2 = DT(2013, 7, 3, 18, 30, 0)

# Functions


def bus_stops(bus):
    w_hnd = urlopen(web_site % bus)
    xml_text = w_hnd.readlines()
    root = ET.fromstring(''.join(xml_text))

    for direction in root:
        for trip in direction:
            for stop in trip[4]:
示例#23
0
def splitfromdate(file, dal):
    output_file = file + "out" + ".txt"
    with open(file + ".txt") as f:
        size = sum(1 for _ in f)
    if dict_formato_caricato['separator'] != "":
        with open(output_file, 'w') as out:
            with open(file + ".txt") as filetxt:
                for line_number, line in tqdm(enumerate(filetxt, 1),
                                              total=size,
                                              unit="lines"):
                    try:
                        params = line.split(" ")
                        dt = params[int(dict_formato_caricato['data_pos'])]
                        try:
                            fromdate = time.strptime(dal, "%d/%m/%Y")
                            linedate = time.strptime(dt, "%d/%m/%Y")
                        except ValueError:
                            continue
                        if linedate >= fromdate:
                            out.write(line)
                    except IndexError:
                        print("\n Errore Linea non conforme")
                        print("errore @: " + str(line_number))
                        print(line)
                        continue
        print("job done: " + output_file + " per risultati")
    else:
        if len(dal) != 8 and len(dal) != 6:
            print("Questo Formato di data non e supportato")
            return
        else:
            with open(output_file, 'w') as out:
                with open(file + ".txt") as filetxt:
                    for line_number, line in tqdm(enumerate(filetxt, 1),
                                                  total=size,
                                                  unit="lines"):
                        try:
                            dt = line[int(dict_formato_caricato['data_start']):
                                      int(dict_formato_caricato['data_end']) +
                                      1]
                            try:
                                if len(dt) == 8:
                                    linedate = DT(int(dt[4:8]), int(dt[2:4]),
                                                  int(dt[0:2]))
                                    fromdate = DT(int(dal[4:8]), int(dal[2:4]),
                                                  int(dal[0:2]))
                                elif len(dt) == 6:
                                    linedate = DT(int(dt[4:6]), int(dt[2:4]),
                                                  int(dt[0:2]))
                                    fromdate = DT(int(dal[4:6]), int(dal[2:4]),
                                                  int(dal[0:2]))
                            except ValueError:
                                continue
                            if linedate >= fromdate:
                                out.write(line)
                        except IndexError:
                            print("\n Errore Linea non conforme")
                            print("errore @: " + str(line_number))
                            print(line)
                            continue
        print("job done: " + output_file + " per risultati")
示例#24
0
    def test_datetimes(self):
        self.assertEqual(
            compute_from_string('2015/07/09').datetime, DT(2015, 7, 9))
        self.assertEqual(
            compute_from_string('2015/07/10 00:00').datetime, DT(2015, 7, 10))
        self.assertEqual(
            compute_from_string('2015/07/11 01:45').datetime,
            DT(2015, 7, 11, 1, 45))
        self.assertEqual(
            compute_from_string('2015/07/09 14:30').datetime,
            DT(2015, 7, 9, 14, 30))
        self.assertEqual(
            compute_from_string('2015/07/09 14:30:26').datetime,
            DT(2015, 7, 9, 14, 30, 26))
        self.assertEqual(
            compute_from_string('2015/07/09 2:15pm').datetime,
            DT(2015, 7, 9, 14, 15))
        self.assertEqual(
            compute_from_string('2015/07/09 3am').datetime, DT(2015, 7, 9, 3))
        self.assertEqual(
            compute_from_string('2015/07/09 12am').datetime, DT(2015, 7, 9))
        self.assertEqual(
            compute_from_string('2015/07/31 12pm').datetime,
            DT(2015, 7, 31, 12))

        self.assertEqual(
            compute_from_string('2015-07-31').datetime, DT(2015, 7, 31))
        self.assertEqual(
            compute_from_string('2015-07-31 01:23').datetime,
            DT(2015, 7, 31, 1, 23))
        self.assertEqual(
            compute_from_string('2015-07-31 01:23:45').datetime,
            DT(2015, 7, 31, 1, 23, 45))
        self.assertEqual(
            compute_from_string('2015-07-31T01:23:45').datetime,
            DT(2015, 7, 31, 1, 23, 45))
        self.assertEqual(
            compute_from_string('20150731T0123').datetime,
            DT(2015, 7, 31, 1, 23))
        self.assertEqual(
            compute_from_string('20150731T012345').datetime,
            DT(2015, 7, 31, 1, 23, 45))

        self.assertDatetimesEqual(
            compute_from_string('now').datetime, DT.now())
        self.assertDatetimesEqual(
            compute_from_string('today').datetime,
            DT.combine(datetime.date.today(), datetime.time()))
        self.assertEqual(compute_from_string('epoch').datetime, DT(1970, 1, 1))
示例#25
0
import traceback
from constants import *
from padherder_sync import *
from datetime import datetime as DT
from datetime import timedelta
from datetime import tzinfo


def first_sunday_on_or_after(dt):
    days_to_go = 6 - dt.weekday()
    if days_to_go:
        dt += timedelta(days_to_go)
    return dt


DSTSTART_2007 = DT(1, 3, 8, 2)
DSTEND_2007 = DT(1, 11, 1, 1)
ZERO = timedelta(0)
HOUR = timedelta(hours=1)


class USTimeZone(tzinfo):
    def __init__(self, hours, reprname, stdname, dstname):
        self.stdoffset = timedelta(hours=hours)
        self.reprname = reprname
        self.stdname = stdname
        self.dstname = dstname

    def __repr__(self):
        return self.reprname
示例#26
0
        TableColumn(field='sym',title='Symbols',width=70),
        TableColumn(field='gmtstamp',title='GMT Timestamp',formatter=DateFormatter(format="%F %T"),width=180),
        TableColumn(field='date',title='Date',formatter=DateFormatter(format="%Y-%m-%d"),width=120),
        TableColumn(field='ret',title='Daily Return',formatter=NumberFormatter(format='0.00%',text_align='right'),width=80)
        ]
searchResult = DataTable(source=searchResultTable,columns=searchResultColumns,width=2*ww,height=1000)
lineSrc = ColumnDataSource(data={'t':[],'i':[]})
spanSrc = ColumnDataSource(data={'x':[]})
retPlotHover = HoverTool(tooltips=[('headline','@headline')])
retPlot = figure(plot_width=250,plot_height=100,tools=[retPlotHover],x_axis_type='datetime')
solrButton = CheckboxButtonGroup(labels=["solr"], active=[0])
selBox1 = Select(title="Previous Categories:", value="", options=[""])
selBox2 = Select(title="Categories:", value="", options=[""])
if datePick1.value:
    date1 = datePick1.value
    dt1 = DT(date1.year,date1.month,date1.day) - timedelta(days=20)
    retPlot.x_range.start=dt1
if datePick2.value:
    date2 = datePick2.value
    dt2 = DT(date2.year,date2.month,date2.day) + timedelta(days=10)
    retPlot.x_range.end=dt2
retPlot.circle(x='gmtstamp',y='ret',size=7,fill_color='lightskyblue',source=searchResultTable)

# actions
def searchNews1():
    errBox.text = 'Searching...'
    qwords = searchBox.value
    return searchNews(qwords,None)
def searchNews2():
    errBox.text = 'Searching for {}...'.format(searchBox.value)
    qwords = searchBox.value
示例#27
0
subdirs  = ['FC0days' , 'FC1days' , 'FC2days' , 'FC3days' , 'FC4days' , 'FC5days',\
                        'PFC1days', 'PFC2days', 'PFC3days', 'PFC4days', 'PFC5days']
Cfields  = ['RMSE_both_ice', 'Bias_both_ice', 'RMSE_either_ice', 'Bias_either_ice']
Ufields  = ['Maximum_total_width', 'Mean_intersecting_width', 'Mean_total_width',\
            'Maximum_intersecting_width', 'Total_perimeter', 'Total_area']

Ofields  = 1*Ufields
Bfields  = Ufields[1:3]
akey     = Ufields[-1]  # area


show  = 0
if 0:
   # reduce period plotted
   dto_lims = [DT(2017,1,1),DT(2017,3,12)]
   Mstep    = 1
else:
   # full period plotted
   dto_lims = [DT(2016,1,1),DT(2017,3,12)]
   Mstep    = 2

M0       = dto_lims[0].month
xlim     = []
refdate  = DT(2010,1,1)
tfac     = 1./(24*3600) # seconds to days
for dto in dto_lims:
   xlim.append((dto-refdate).total_seconds()*tfac)


for ng in range(2):
示例#28
0
def DTS(*args, **kw):
    """ Returns a unix-timestamp-like time """
    return dt_to_sec(DT(*args, **kw))
示例#29
0
from datetime import datetime as DT

dates = [DT(2012, 12, 15), DT(1987, 8, 20), DT(1965, 2, 28), DT(2012, 6, 27)]


def is_2012(arg):
    return arg.year == 2012


dt_2012 = filter(is_2012, dates)

print(next(dt_2012))
print(next(dt_2012))
示例#30
0
from datetime import datetime as DT

birthdays = [
    DT(2012, 4, 29),
    DT(2006, 8, 9),
    DT(1978, 5, 16),
    DT(1981, 8, 15),
    DT(2001, 7, 4),
    DT(1999, 12, 30)
]


def is_over_13(dt):
    '''Returns True or False if >= 4745 (days)'''
    today = DT.today()
    return (today - dt).days >= 4745


def date_string(dt):
    '''Returns formatted datetime, as string'''
    return dt.strftime("%B %d")


birth_dates = map(date_string, filter(is_over_13, birthdays))

print(list(birth_dates))