else: print "### No need to correct!" if __name__ == "__main__": """ If no arguments exist, input startTime from parameter.py """ if len(sys.argv) < 2: print "### Used default parameters for startTime!" else: startTime = sys.argv[1] startTime = startTime[0:10] + "0000" startTime = timeHrAdd(startTime, -1) stopsTime = timeHrAdd(startTime, 1) print "### Used startTime =", startTime """ Initialize the required Databases and the main function""" hbD = ae.hbase(HBaseTable_Downtime, hbaseIP) db = ae.mongo(Mongo_N71_DB, mongoIP, mongoPort) """ Read the recorded last query time and the latest insert time """ LQT = db.find(LastQueryTime, {}) oldLastQueryTime = LQT[0]["LastQueryTime"] print "### IMPORTANT ### LastQueryTime = ", oldLastQueryTime resD, newLastQueryTime = hbD.ScanReturnList_InserTime(oldLastQueryTime) if resD: startEventTime = resD[0]['key'].split("_")[0] stopsEventTime = resD[-1]['key'].split("_")[0] data = {"LastQueryTime" : timeSecAdd(newLastQueryTime, 1)} time = resD[0]['key'].split("_")[0] print "### Updated from "+ startEventTime+" to "+stopsEventTime while resD: try:
stat = each.split("_")[1] summary = db.find(StationSummary, {"station_name":stat, "line":line}) if summary: query = {"station_name":stat, "line":line} data = { "update_time": update_time, "downtime_5days" : downtime_5days[each] } db.update(StationSummary, query, data) else: downtime = downtime_5days[each] data = { "station_name": stat, "line": line, "update_time": update_time, "downtime_5days" : downtime_5days[each], "downtime_24hour": 0, "downtime_shift": 0, "downtime_day": 0 } db.insert(StationSummary, data) yesterday = timeHrAdd(yesterday, 1) if __name__ == "__main__": table = "test" hbD = ae.hbase("N71_AE_Downtime", hbaseIP) #resD, newLastQueryTime = hbD.ScanReturnList_InserTime("20150428143001") resD = hbD.ScanReturnList("20150418110443", "20150418140040") db = ae.mongo(Mongo_N71_DB, mongoIP, mongoPort) aggregateDowntime(resD, db) StationSummarize("20150423000000", db)