def _state_graph_widgets(self,
                             inst_id,
                             widget_name,
                             instance=None,
                             start=None,
                             end=None):
        """
        Internal function to make calls for state widget functions
        @param - inst_id
        @param - widget_name
        @param - instance
        @param - start ( Python datetime object)
        @param - end ( Python datetime object)
        """
        if not self._is_initialized():
            return None

        data_dict = {}

        if start and end:
            data_dict['start'] = datetime_to_epoch(start)
            data_dict['end'] = datetime_to_epoch(end)

        if instance:
            data_dict['instance'] = instance

        request_url = self.WIDGETS_ENDPOINT.format(inst_id=inst_id,
                                                   widget_type=widget_name)
        widgets = self._send_query_request(request_url, data_dict)
        return widgets
    def graph_widgets(self,
                      inst_id,
                      measurement_codes,
                      instance=None,
                      start=None,
                      end=None):
        """
        Returns graph widgets for given measurements codes
        @param - inst_id (installation id)
        @param - measurement_codes (A List of the measurent codes)
        """
        if type(measurement_codes) is not list:
            raise Exception("The measurement codes should be an array")

        if not self._is_initialized():
            return None

        data_dict = {'attributeCodes[]': measurement_codes}

        if instance:
            data_dict['instance'] = instance

        if start and end:
            data_dict['start'] = datetime_to_epoch(start)
            data_dict['end'] = datetime_to_epoch(end)

        request_url = self.WIDGETS_ENDPOINT.format(inst_id=inst_id,
                                                   widget_type='Graph')
        widgets = self._send_query_request(request_url, data_dict)
        return widgets
    def get_consumption_stats(self, inst_id, start=None, end=None):
        """
        Returns the consumptions statistics for a given site
        @params - inst_id (installation id)
        @params - start ( A python datetime to start from)
        @params - end (A python datetime to stop to)
        """
        if not self._is_initialized():
            return None

        if start and end:
            data_dict = {
                'type': 'consumption',
                'start': datetime_to_epoch(start),
                'end': datetime_to_epoch(end)
            }
        else:
            data_dict = {
                'type': 'consumption',
            }

        request_url = self.QUERY_ENDPOINT.format(inst_id=inst_id)
        stats = self._send_query_request(request_url, data_dict=data_dict)
        logger.debug("The stats consumption got from the api endpoint is %s " %
                     stats)
        return stats
Beispiel #4
0
 def get_data(self):
     return {
         'id': self.key.id(),
         'name': self.name,
         'fee': self.fee,
         'start_date_epoch': datetime_to_epoch(self.start_date),
         'participants': [participant.get_data() for participant in ndb.get_multi(self.participants)]
     }
Beispiel #5
0
 def testStillOpen_mktime(self):
     c = self.setup()
     door = c.get_door("right")
     door.tis[Utils.STILLOPEN] = Utils.round_up_minutes(Utils.get_time())
     curr_time = datetime.datetime.strptime("06-14-2020 13:11:05",
                                            Utils.DATEFORMAT)
     door.tis[Utils.STILLOPEN] = Utils.round_up_minutes(
         Utils.datetime_to_epoch(curr_time))
     self.assertEqual(1592162100.0, door.tis[Utils.STILLOPEN])
Beispiel #6
0
    def testIsTimeExpired(self):
        self.setup()
        tis = Utils.datetime_to_epoch(
            datetime.datetime.strptime("06-14-2020 11:00:00",
                                       Utils.DATEFORMAT))
        alert_time = 1200  # 20 mins
        curr_time = Utils.datetime_to_epoch(
            datetime.datetime.strptime("06-14-2020 11:10:00",
                                       Utils.DATEFORMAT))
        self.assertFalse(Utils.is_time_expired(tis, alert_time, curr_time))

        curr_time = Utils.datetime_to_epoch(
            datetime.datetime.strptime("06-14-2020 11:20:01",
                                       Utils.DATEFORMAT))
        self.assertTrue(Utils.is_time_expired(tis, alert_time, curr_time))

        alert_time = 0
        self.assertTrue(Utils.is_time_expired(tis, alert_time, curr_time))
Beispiel #7
0
    def get_data(self, detail_level="simple"):
        data = {
            'id': self.key.id(),
            'winning_faction': self.winning_faction,
            'type': self.type,
            'what': self.what(),
            'date_epoch': datetime_to_epoch(self.date),
            'state': self.state()
        }

        if detail_level == "full":
            if hasattr(self, "cached_combatants"):
                match_combatants = self.cached_combatants
            else:
                match_combatants = MatchCombatant.query(MatchCombatant.match == self.key).fetch()
            data.update({
                'combatants': [match_combatant.get_data() for match_combatant in match_combatants],
                'bets': [bet.get_data() for bet in Bet.query(Bet.match == self.key)],
                'logs': self.logs
            })

        return data