Beispiel #1
0
 def test_dateDataListToList(self):
     metricName = "metric"
     dateDataList = [{metricName: 30}, {metricName: 40}, {metricName: 50}]
     resList = util.dateDataListToList(dateDataList, metricName)
     self.assertEqual(resList[0], 30)
     self.assertEqual(resList[1], 40)
     self.assertEqual(resList[2], 50)
Beispiel #2
0
def getdayDifference(lobName, granularity=0):
  fromDate = util.jsStringToDate("2016-12-15T00:00:00.000Z").replace(hour=0, minute=0, second=0)
  toDate = util.jsStringToDate("2017-01-05T00:00:00.000Z").replace(hour=0, minute=0, second=0)
  response = {}
  mongoQuery = data_query.DateRangeGroupQuery(fromDate, toDate, [lobName], granularity)
  data = mongoQuery.execute()
  metrics = {}
  metricsList = mongoQuery.metrics
  metadata = mongoQuery.metadata
  data = data_query.medianDateRange(fromDate, toDate, lobName, granularity, data)
  return util.dateDataListToList(data, "dayDifference")
Beispiel #3
0
def getData(flows, fromDate, toDate):
    flow = flows[0]
    flowName = flow["name"]
    mongoQuery = data_query.DateRangeGroupQuery(fromDate,
                                                toDate,
                                                flows,
                                                granularity=granularity)
    data = mongoQuery.execute()
    metricsList = mongoQuery.metrics
    metadata = mongoQuery.metadata
    if len(flows) == 1:
        metric = metricsList[0]
        flowLevelQuery = data_query.FlowLevelDateRangeQuery(
            fromDate, toDate, flows, metadata["granularity"], data)
        flowLevelData = flowLevelQuery.execute()
        data = util.merge2DateLists(flowLevelData, None, data, None)
        metricsList.extend(flowLevelQuery.metrics)
        outageQuery = data_query.OutageDateRangeQuery(fromDate, toDate,
                                                      flows[0],
                                                      metadata["granularity"])
        outageQuery.setPrecomputedData(data, metric)
        outageList = outageQuery.execute()
        data = util.merge2DateLists(outageList, [outageQuery.metric], data,
                                    None)
        metricsList.append(outageQuery.metric)

    dates = list(
        map(lambda x: x.strftime("%d.%m %H:%M"),
            util.dateDataListToList(data, "_id")))
    data1 = util.dateDataListToList(data, flowName)
    expected = util.dateDataListToList(data, "expected")
    dataTicks = []
    dataTickPos = []
    for i in range(0, len(dates)):
        if True:
            dataTicks.append(dates[i])
            dataTickPos.append(i)
    return data1, expected, dataTicks, dataTickPos
        for x, y in zip(windowData, weights):
            s += x * y
        average = s / sum(weights)
        output.append(average)
    return output


fromDate = util.stringToTime("02.03.2017 00:00:00")
toDate = util.stringToTime("03.03.2017 00:00:00")
granularity = 15
q = DateRangeGroupQuery(
    fromDate, toDate,
    [MediationConfig.getLobWithCountry("CZ", "GSM")["flows"]["MSSBRN1A"]],
    granularity)
# q = DateRangeGroupQuery(fromDate, toDate, [MediationConfig.getLobWithCountry("CZ","ACI")["flows"]["GSM"]], granularity)
lob1Data = util.dateDataListToList(q.execute(), "MSSBRN1A")
lob1Data.append(0)
lob1Data.append(0)
lob1Data.append(0)
lob1Data.append(0)
dates = list(
    map(
        lambda x: util.dateToTimeString(x).split("+")[0].split("T")[1].split(
            ":")[0], util.dateDataListToList(q.execute(), "_id")))
dataTicks = []
dataTickPos = []
for i in range(0, len(dates)):
    if i % 4 == 0:
        dataTicks.append(dates[i])
        dataTickPos.append(i)
Beispiel #5
0
            s += x * y
        average = s / sum(weights)
        output.append(average)
    return output


fromDate = util.stringToTime("02.03.2017 00:00:00")
toDate = util.stringToTime("03.03.2017 00:00:00")
granularity = 60
x = MediationConfig.getLobWithCountry("CZ", "GSM")
q = DateRangeGroupQuery(
    fromDate, toDate,
    [MediationConfig.getLobWithCountry("CZ", "DAR")["flows"]["DARE2FEE"]],
    granularity)
# q = DateRangeGroupQuery(fromDate, toDate, [MediationConfig.getLobWithCountry("CZ","ACI")["flows"]["GSM"]], granularity)
lob1Data = util.dateDataListToList(q.execute(), "DARE2FEE")
dates = list(
    map(
        lambda x: util.dateToTimeString(x).split("+")[0].split("T")[1].split(
            ":")[0], util.dateDataListToList(q.execute(), "_id")))
dataTicks = []
dataTickPos = []
for i in range(0, len(dates)):
    if i % 4 == 0:
        dataTicks.append(dates[i])
        dataTickPos.append(i)

# lob1Data=[100,0,0,100,0,0,100,0,0,100,0,0,100,0,0,100,0,0,100,0,0,100,0,0]
plt.figure(figsize=(12, 6))
plt.plot(lob1Data, color="#ff009f", label="actual data")
Beispiel #6
0
    metric = metricsList[0]
    flowLevelQuery = data_query.FlowLevelDateRangeQuery(
        fromDate, toDate, flows, metadata["granularity"], data)
    flowLevelData = flowLevelQuery.execute()
    data = util.merge2DateLists(flowLevelData, None, data, None)
    metricsList.extend(flowLevelQuery.metrics)
    outageQuery = data_query.OutageDateRangeQuery(fromDate, toDate, flows[0],
                                                  metadata["granularity"])
    outageQuery.setPrecomputedData(data, metric)
    outageList = outageQuery.execute()
    data = util.merge2DateLists(outageList, [outageQuery.metric], data, None)
    metricsList.append(outageQuery.metric)

dates = list(
    map(lambda x: x.strftime("%d.%m %H:%M"),
        util.dateDataListToList(data, "_id")))
data1 = util.dateDataListToList(data, flowName)
expected = util.dateDataListToList(data, "expected")
dataTicks = []
dataTickPos = []
for i in range(0, len(dates)):
    if i % 24 == 0:
        dataTicks.append(dates[i])
        dataTickPos.append(i)

plt.figure(figsize=(12, 5))
plt.plot(data1, color="red", label=lobName + "-" + flowName)
plt.plot(expected, color="blue", label="expected")
plt.plot(util.dateDataListToList(data, "dayAverage"),
         color="orange",
         label="day average")
    metric = metricsList[0]
    flowLevelQuery = data_query.FlowLevelDateRangeQuery(
        fromDate, toDate, flows, metadata["granularity"], data)
    flowLevelData = flowLevelQuery.execute()
    data = util.merge2DateLists(flowLevelData, None, data, None)
    metricsList.extend(flowLevelQuery.metrics)
    outageQuery = data_query.OutageDateRangeQuery(fromDate, toDate, flows[0],
                                                  metadata["granularity"])
    outageQuery.setPrecomputedData(data, metric)
    outageList = outageQuery.execute()
    data = util.merge2DateLists(outageList, [outageQuery.metric], data, None)
    metricsList.append(outageQuery.metric)

dates = list(
    map(lambda x: x.strftime("%d.%m %H:%M"),
        util.dateDataListToList(data, "_id")))
data1 = util.dateDataListToList(data, flowName)
expected = util.dateDataListToList(data, "expected")
dayDifference = util.dateDataListToList(data, "dayDifference")
tickDifference = util.dateDataListToList(data, "tickDifference")
dataTicks = []
dataTickPos = []
for i in range(0, len(dates)):
    if i % 12 == 0:
        dataTicks.append(dates[i])
        dataTickPos.append(i)

plt.figure(figsize=(12, 9))

plt.subplot(211)
plt.xticks(dataTickPos, dataTicks, rotation=25)