def __init__(self, fromDate, toDate, flows, granularity, data):
     super().__init__()
     self.fromDate = util.resetDateTimeMidnight(fromDate)
     self.toDate = util.resetDateTimeMidnight(toDate)
     self.flows = flows
     self.granularity = granularity
     self.data = data
     self.metrics = []
 def __init__(self, fromDate, toDate, flow, granularity):
     super().__init__()
     self.fromDate = util.resetDateTimeMidnight(fromDate)
     self.toDate = util.resetDateTimeMidnight(toDate)
     self.flow = flow
     self.granularity = granularity
     self.metric = "status"
     self.tickDict = {}
     from mediation.flow_analyzer import FlowAnalyzer
     self.flowAnalyzer = FlowAnalyzer(self.flow, self.granularity)
Example #3
0
 def test_resetDateTimeMidnight(self):
     self.assertEqual(
         util.resetDateTimeMidnight(
             util.stringToTime("01.02.2017 02:00:00")),
         util.stringToTime("01.02.2017 00:00:00"))
     self.assertEqual(
         util.resetDateTimeMidnight(
             util.stringToTime("02.02.2017 03:00:00")),
         util.stringToTime("02.02.2017 00:00:00"))
     self.assertEqual(
         util.resetDateTimeMidnight(
             util.stringToTime("26.03.2017 04:00:00")),
         util.stringToTime("26.03.2017 00:00:00"))
Example #4
0
 def __init__(self, dates, flows, granularity=0):
     self.query = None
     self.coll = mongo.traffic()
     self.metrics = []
     self.dataPaths = []
     self.dates = [util.resetDateTimeMidnight(d) for d in dates]
     self.flows = flows
     self.granularity = int(granularity)
     self.createDataPathAndOutputs2()
     self.metadata = {}
Example #5
0
 def __init__(self, dates, flows, granularity=0):
     self.query = None
     self.coll = mongo.traffic()
     self.flow = flows[0]
     self.metrics = []
     self.dates = [util.resetDateTimeMidnight(d) for d in dates]
     self.metric = self.flow["name"]
     self.metrics.append(self.metric)
     self.granularity = int(granularity)
     self.metadata = {}
     self.determinateGranularity()
 def createMatchObject(self):
     orMatches = []
     for date in self.dates:
         orMatches.append({
             "_id": {
                 "$gte":
                 date,
                 "$lt":
                 util.resetDateTimeMidnight(date +
                                            datetime.timedelta(days=1))
             }
         })
     return {"$match": {"$or": orMatches}}
Example #7
0
    def execute(self):
        startTime = util.startTime()
        resultDict = self._executePythonAggregateQuery()
        diff = util.timeDifference(startTime)
        #print(diff, ",")
        nullObject = {self.metric: 0}
        finalResultDict = {}
        for date in self.dates:
            d = date
            until = util.resetDateTimeMidnight(date +
                                               datetime.timedelta(days=1))
            while d < until:
                if d not in resultDict:
                    finalResultDict[d] = {**nullObject, **{"_id": d}}
                else:
                    finalResultDict[d] = resultDict[d]
                d = util.getNextTic(d, self.granularity)

        result = sorted(finalResultDict.values(), key=lambda x: x["_id"])
        return result
Example #8
0
import datetime

import pytz
from dateutil import tz

from common import util
prg = pytz.timezone('Europe/Prague')
dateutilPrg = tz.gettz('Europe/Prague')
utc = pytz.timezone('UTC')
cet = pytz.timezone('CET')
# t = util.stringToTime("01.01.2017 01:00:00")
# print(t)
day = util.resetDateTimeMidnight(util.stringToTime("26.03.2017 07:00:00"))
day2 = util.resetDateTimeMidnight(
    util.stringToTime("26.03.2017 00:00:00") + datetime.timedelta(days=1))
print(day.astimezone(utc))
print(
    util.resetDateTimeMidnight(day +
                               datetime.timedelta(days=1)).astimezone(utc))
x = (util.stringToTime("27.03.2017 00:00:00") +
     datetime.timedelta(days=1)).astimezone(utc)

# print(prg.localize(datetime.datetime(2017, 3, 26, 1, 0, 0, 0)))
# print(prg.localize(datetime.datetime(2017, 3, 26, 2, 0, 0, 0)))
# print(prg.localize(datetime.datetime(2017, 3, 26, 3, 0, 0, 0)))
# print(prg.localize(datetime.datetime(2017, 3, 26, 2, 0, 0, 0)) == prg.localize(datetime.datetime(2017, 3, 26, 3, 0, 0, 0)))
# print("--")
# print(datetime.datetime(2017, 3, 26, 0, 0, 0, 0,cet).astimezone(prg))
# print(datetime.datetime(2017, 3, 26, 1, 0, 0, 0,cet).astimezone(prg))
# print(datetime.datetime(2017, 3, 26, 2, 0, 0, 0,cet).astimezone(prg))
# print(datetime.datetime(2017, 3, 26, 3, 0, 0, 0,cet).astimezone(prg))