Exemple #1
0
 def testTransformMonthlyFull(self):
     test_data = json.loads(
         '{"etat":{"valeur":"termine"},"graphe":{"decalage":0,"puissanceSouscrite":0,"periode":{"dateFin":"01/12/2019","dateDebut":"01/12/2018"},"data":[{"valeur":1946.421,"ordre":0},{"valeur":2985.301,"ordre":1},{"valeur":2116.03,"ordre":2},{"valeur":713.889,"ordre":3},{"valeur":987.182,"ordre":4},{"valeur":722.873,"ordre":5},{"valeur":510.548,"ordre":6},{"valeur":400.053,"ordre":7},{"valeur":485.04,"ordre":8},{"valeur":386.553,"ordre":9},{"valeur":579.89,"ordre":10},{"valeur":1343.156,"ordre":11},{"valeur":43.476,"ordre":12}]}}'
     )
     l = Data(cookies=None, url="http://testme/data")
     data = l._transform_data(
         Data.RESOURCE_MONTHLY, test_data["graphe"],
         (datetime.datetime(year=2018, month=12, day=1).replace(
             tzinfo=pytz.timezone("Europe/Paris")),
          datetime.datetime(year=2019, month=12, day=1).replace(
              tzinfo=pytz.timezone("Europe/Paris"))))
     log.debug(data)
     self.assertEqual(len(data), 12)
     self.assertEqual(
         data[0]["date"],
         datetime.datetime.strptime(
             "1/12/2018",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[0]["value"], 1946.421)
     self.assertEqual(
         data[1]["date"],
         datetime.datetime.strptime(
             "1/1/2019",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[1]["value"], 2985.301)
     self.assertEqual(
         data[2]["date"],
         datetime.datetime.strptime(
             "1/2/2019",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[2]["value"], 2116.03)
Exemple #2
0
 def testTransformMonthlyOffset(self):
     test_data = json.loads(
         '{"etat":{"valeur":"termine"},"graphe":{"decalage":4,"puissanceSouscrite":0,"periode":{"dateFin":"01/12/2019","dateDebut":"01/09/2019"},"data":[{"valeur":-1,"ordre":1},{"valeur":-1,"ordre":2},{"valeur":-1,"ordre":3},{"valeur":-1,"ordre":4},{"valeur":386.553,"ordre":4},{"valeur":579.89,"ordre":5},{"valeur":1343.156,"ordre":6},{"valeur":43.476,"ordre":7},{"valeur":-1,"ordre":9},{"valeur":-1,"ordre":10},{"valeur":-1,"ordre":11},{"valeur":-1,"ordre":12}]}}'
     )
     l = Data(cookies=None, url="http://testme/data")
     data = l._transform_data(
         Data.RESOURCE_MONTHLY, test_data["graphe"],
         (datetime.datetime(year=2019, month=9, day=1).replace(
             tzinfo=pytz.timezone("Europe/Paris")),
          datetime.datetime(year=2019, month=12, day=1).replace(
              tzinfo=pytz.timezone("Europe/Paris"))))
     log.debug(data)
     self.assertEqual(len(data), 3)
     self.assertEqual(
         data[0]["date"],
         datetime.datetime.strptime(
             "1/09/2019",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[0]["value"], 386.553)
     self.assertEqual(
         data[1]["date"],
         datetime.datetime.strptime(
             "1/10/2019",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[1]["value"], 579.89)
     self.assertEqual(
         data[2]["date"],
         datetime.datetime.strptime(
             "1/11/2019",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[2]["value"], 1343.156)
Exemple #3
0
    def testTransformData(self):
        test_data = {
            "etat": {
                "valeur": "termine"
            },
            "graphe": {
                "decalage":
                0,
                "puissanceSouscrite":
                9,
                "periode": {
                    "dateFin": "14/11/2019",
                    "dateDebut": "11/11/2019"
                },
                "data": [{
                    "valeur": 4.154,
                    "ordre": 1
                }, {
                    "valeur": 4.508,
                    "ordre": 2
                }, {
                    "valeur": 4.210,
                    "ordre": 3
                }, {
                    "valeur": 4.322,
                    "ordre": 4
                }, {
                    "valeur": 4.382,
                    "ordre": 5
                }]
            }
        }

        l = Data(cookies=None, url="http://testme/data")

        data = l._transform_data(Data.RESOURCE_HOURLY, test_data["graphe"])
        log.debug(data)
        self.assertEqual(len(data), 5)
        self.assertEqual(
            data[0]["date"],
            datetime.datetime.strptime(
                "11/11/2019 00:00", "%d/%m/%Y %H:%M").replace(
                    tzinfo=pytz.timezone("Europe/Paris")))
        self.assertEqual(data[0]["value"], 4.154)
        self.assertEqual(
            data[4]["date"],
            datetime.datetime.strptime(
                "11/11/2019 02:00", "%d/%m/%Y %H:%M").replace(
                    tzinfo=pytz.timezone("Europe/Paris")))
        self.assertEqual(data[4]["value"], 4.382)
Exemple #4
0
 def testTransformYearly(self):
     test_data = json.loads(
         '{"etat":{"valeur":"termine"},"graphe":{"decalage":0,"puissanceSouscrite":0,"periode":{"dateFin":"02/12/2019","dateDebut":"02/12/2016"},"data":[{"valeur":-2,"ordre":0},{"valeur":-2,"ordre":1},{"valeur":4148.506,"ordre":2},{"valeur":11327.075,"ordre":3}]}}'
     )
     l = Data(cookies=None, url="http://testme/data")
     data = l._transform_data(
         Data.RESOURCE_YEARLY, test_data["graphe"],
         (datetime.datetime(year=2018, month=1, day=1).replace(
             tzinfo=pytz.timezone("Europe/Paris")),
          datetime.datetime(year=2019, month=1, day=1).replace(
              tzinfo=pytz.timezone("Europe/Paris"))))
     log.debug(data)
     self.assertEqual(len(data), 1)
     self.assertEqual(
         data[0]["date"],
         datetime.datetime.strptime(
             "1/1/2018",
             "%d/%m/%Y").replace(tzinfo=pytz.timezone("Europe/Paris")))
     self.assertEqual(data[0]["value"], 4148.506)