Пример #1
0
    db.drop(MongoStationIP_Collection)
    db.drop(BySubStationName_Shifts)
    db.drop(ByStationIP_Shifts)
    db.drop(BySubStationName_Rank)
    db.drop(ByStationIP_Rank)
    db.drop(MongoCheck_Collection)
    db.drop(StationSummary)    
    db.drop(ByStation) 
    db.drop(ByStation_Shifts)    
    db.drop(LastResult) 
    
# Main Function
if __name__ == "__main__":
    name = Mongo_N71_DB
    #createDatabase(name)
    db = ae.mongo(name, mongoIP, mongoPort)
    if len(sys.argv) < 2:
        create = 1
    else:
        create = int(sys.argv[1])
    if create:
        print "Initialize all collections!"
        createDatabase(Mongo_N71_DB)
        createBySubStationName(db)
        createByStationIP(db)
        createBySubStationName_Shifts(db)
        createByStationIP_Shifts(db)
        createCheck(db)
        createLastMode(db)
        createLastTime(db)
        createSummary(db)
Пример #2
0
            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:
                resDTmp = []
Пример #3
0
                        ips[ip]["downtime_error"][code]["duration"] += each["downtime_error"][code]["duration"]
                ips[ip]["downtime"] += each["downtime"]
        resSt = db.find(ByStation, {"date":dt[0:8], "time":dt[8:14]})
        for each in resSt:
            station = each["line"] + "_" + each["station_name"]
            if station not in stations:
                stations[station] = each
                stations[station]['date'] = startTime[0:8]
                del stations[station]["time"]
                stations[station]["shift"] = shift
            else:
                stations[station]["downtime"] += each["downtime"]
            #if each["station_name"] == "BBS":
            #    print each
            #    print each["downtime"]
            #    print stations[station]["downtime"]
    return subs, ips, stations

def MRmain(db, startTime, stopsTime, subCol, ipCol, shiftTime, shift):
    subs, ips, stations = Aggregate(db, startTime, stopsTime, shiftTime, shift)
    return subs, ips, stations
    
## Test
if __name__ == "__main__":
    table = "test"
    db = ae.mongo(table, mongoIP, mongoPort)    
    startTime = "20150403140000"
    stopsTime = "20150422140000"
    s = MongoSubStationName_Collection
    i = MongoStationIP_Collection
    MRmain(db, startTime, stopsTime, s, i)