Esempio n. 1
0
    def execute_request(self, request):
        instruction = request.get('inst')
        now_string = request.get('now', None)
        if now_string:
            now = cet_from_string(now_string)
            test_file = request.get('file', 'ignore')
        else:
            now = now_cet()
            test_file = None

        if instruction == 'avt':
            if self.answer_avt(now):
                increase_counter('req_avt_answered')
                self.perform_avt(now, test_file)
            else:
                increase_counter('req_avt_denied')

        elif instruction == 'prio':
            if self.answer_prio(now):
                increase_counter('req_prio_answered')
                self.perform_avt(now, test_file)
            else:
                increase_counter('req_prio_denied')

        elif instruction == 'check':
            mission_id = request.get('sender')
            exp_s = request.get('expected')
            if exp_s:
                expected = cet_from_string(exp_s)
            else:
                expected = now_cet() + timedelta(days=1)
            self.perform_check(mission_id, now, expected, test_file)

        elif instruction == 'console':
            self.perform_avt(now, test_file)
Esempio n. 2
0
    def get(self):
        increase_counter('req_trajectory')
        origin_id = self.request.get('from')
        if not self.validateID(origin_id): return
        destination_id = self.request.get('to')
        if not self.validateID(destination_id): return

        time_string = self.request.get('start', None)
        if time_string is None:
            start_time = now_cet() - timedelta(hours=1)
        else:
            if not self.validateDatetime(time_string): return
            start_time = cet_from_string(time_string)

        span_string = self.request.get('span', None)
        if span_string is None:
            time_span = timedelta(hours=3)
        else:
            if not self.validateDigit(span_string): return
            time_span = timedelta(hours=int(span_string))

        output_string = json.dumps(
            self.trajectory_dict(origin_id, destination_id, start_time,
                                 time_span))
        self.response.out.write(output_string)
Esempio n. 3
0
    def update_object(self, existing_object, name):
        if existing_object.status != self.stop_status:
            existing_object.status = self.stop_status
            self.changes = True

        delay = minutes_from_RFC3339_string(self.delay)
        if existing_object.delay_dep != delay:
            existing_object.delay_dep = delay
            self.changes = True

        if existing_object.destination != self.destination:
            existing_object.destination = self.destination
            self.changes = True

        if existing_object.alteredDestination != self.alt_destination:
            existing_object.alteredDestination = self.alt_destination
            self.changes = True

        if existing_object.platform != self.platform:
            existing_object.platform = self.platform
            existing_object.platformChange = self.platform_change
            self.changes = True

        departure = cet_from_string(self.departure)
        if departure != existing_object.departure:
            existing_object.departure = departure
            self.changes = True
        if not hasattr(self,
                       'last_departure') or departure > self.last_departure:
            self.last_departure = departure
Esempio n. 4
0
 def get(self):
     user = users.get_current_user()
     if user:
         logging.info('stats request by logged in user: %s' %
                      user.nickname())
     else:
         logging.info('stats request by anonymous user')
     now_string = self.request.get('now')
     if now_string:
         now = cet_from_string(now_string)
     else:
         now = now_cet()
     self.response.out.write(json.dumps(TASeries.statistics(now)))
Esempio n. 5
0
 def fromRepr(cls, dictionary):
     self = cls()
     self.station_id = dictionary.get('si', None)
     self.mission_id = dictionary.get('mi', None)
     self.status = dictionary.get('s', 0)
     a = dictionary.get('a', None)
     if a: self.arrival = cet_from_string(a)
     v = dictionary.get('v', None)
     if v: self.departure = cet_from_string(v)
     now = dictionary.get('now', None)
     if now: self.now = cet_from_string(now)
     self.delay_arr = dictionary.get('da', 0.0)
     self.delay_dep = dictionary.get('dv', 0.0)
     self.destination = dictionary.get('de', None)
     self.alteredDestination = dictionary.get('ad', None)
     self.platform = dictionary.get('p', None)
     if self.platform != None:
         self.platformChange = False
     else:
         self.platform = dictionary.get('pc', None)
         if self.platform != None:
             self.platformChange = True
     return self
Esempio n. 6
0
    def start_xml_element(self, name, attrs):
        if name == 'routeItems':
            self.from_rail_atlas = True

        elif name == 'TAStation':
            self.from_rail_atlas = True

        elif name == 'station':
            if self.from_rail_atlas:
                identifier = attrs.get('id')
                comps = identifier.split('.')
                self.country = comps[0]
                self.code = comps[1]
                self.name = attrs.get('name')
                self.importance = int(attrs.get('importance'))

        elif name == 'unit_test':
            now_string = attrs.get('timestamp')
            self.now = cet_from_string(now_string)
Esempio n. 7
0
    def get(self):
        increase_counter('req_departures')
        series_id = self.request.get('series')
        if not self.validateID(series_id):
            self.reject()
            return
        origin_id = self.request.get('from')
        if not self.validateID(origin_id):
            self.reject()
            return

        direction_string = self.request.get('dir')
        if direction_string == 'up':
            direction = Direction.up
        elif direction_string == 'down':
            direction = Direction.down
        else:
            self.reject()
            return

        time_string = self.request.get('start', None)
        if time_string is None:
            start_time = now_cet() - timedelta(hours=1)
        else:
            if not self.validateDatetime(time_string): return
            start_time = cet_from_string(time_string)

        span_string = self.request.get('span', None)
        if span_string is None:
            time_span = timedelta(hours=3)
        else:
            if not self.validateDigit(span_string): return
            time_span = timedelta(hours=int(span_string))

        series = TASeries.get(series_id)
        if not series:
            self.reject()
            return
        output_string = json.dumps(
            self.departures_dict(series, origin_id, direction, start_time,
                                 time_span))
        self.response.out.write(output_string)
Esempio n. 8
0
    def perform(self):
        instruction = self.request.get('inst')

        if instruction == 'fetch':
            if self.resource:
                self.resource.import_schedule()
                self.response.out.write('<a href=\"/console/series?id=%s\">terug naar serie</a>' % self.resource.id)
            else:
                TASeries.import_xml('series.data/series.xml')
                self.redirect('/console/series')
            return

        if not self.resource:
            logging.warning('Resource not found.')
            return

        if instruction == 'new_day':
            now_string = self.request.get('now')
            if now_string:
                now = cet_from_string(self.request.get('now'))
            else:
                now = now_cet()
            self.resource.activate_new_day(now)

        elif instruction == 'delete_point':
            sender = self.request.get('sender')
            self.resource.delete_point(sender)
            self.response.out.write('<a href=\"/console/series?id=%s\">terug naar serie</a>' % self.resource.id)

        elif instruction == 'optimize_odids':
            changed_missions = []
            for mission in self.resource.up_missions + self.resource.down_missions:
                mission.optimize_odIDs_dictionary()
                if mission.needs_datastore_put:
                    changed_missions.append(mission)
            memcache.set_multi(TAMission.dictionary_from_list(changed_missions), namespace='TAMission')
            db.put(changed_missions)
            self.response.out.write('<a href=\"/console/missions?kind=pattern&series=%s\">terug naar serie</a>' %
                                    self.resource.id)