コード例 #1
0
def printinfo():
    fnamelist = ["../10"+str(v)+".csv" for v in xrange(22,23)]
    cnt = 0
    found = 0
    wholeresult = {}
    # writefile = open("../cleandata","w")

    missloc = {}
    for fname in fnamelist:
        filereader = FileReader(fname)
        alarmcode = filereader.getattridx("ALARMCODE")
        attridx = filereader.getattridx("SUMMARY")
        locidx= filereader.getattridx("LOCATION")
        timeidx = filereader.getattridx("ALARMHAPPENTIME")
        cntidx = 0
        while True:
            tmptran = filereader.readtransection()
            cntidx += 1
            # print cntidx
            if tmptran is None:
                filereader.close()
                break

            summary = tmptran[attridx]
            location = tmptran[locidx]
            if location.startswith("SU6095-SU2551"):
                print "SUMMARY:"
                print summary
                print "--------------"
                print "LOCATION"
                print location
コード例 #2
0
 def loadloc(self):
     filereader = FileReader("../NE_INFO.csv")
     neididx = filereader.getattridx("NE_ID")
     noidx = filereader.getattridx("NE_NO")
     nameidx = filereader.getattridx("NE_NAME")
     ididx = filereader.getattridx("ID_IN_NM")
     self.m_locdata = []
     while True:
         tmptran = filereader.readtransection()
         if tmptran is None:
             break
         innminfo = tmptran[ididx]
         siteididx = innminfo.find("BtsSiteMgr=BCF-")
         if siteididx == -1:
             siteididx = innminfo.find("BtsSiteMgr=")
             if siteididx == -1:
                 innm = "-1"
             else:
                 innm = innminfo[siteididx + len("BtsSiteMgr="):]
         else:
             # innm = innminfo[siteididx+len("BtsSiteMgr=BCF-"):]
             innm = "-1"
         self.m_locdata.append(
             NE(tmptran[noidx], tmptran[nameidx], tmptran[ididx],
                tmptran[neididx]))
コード例 #3
0
    def loadtopo(self):
        self.m_directtopo = {}
        self.m_fatherdata = {}
        self.m_topodict = {}
        filereader = FileReader("../NE_TOPO_INFO.csv")
        neidx = filereader.getattridx("NE_ID")
        parentidx = filereader.getattridx("PARENT_NE_ID")
        empty = 0
        nonempty = 0
        halfempty = 0
        while True:
            tmptran = filereader.readtransection()
            if tmptran is None:
                break
            neid = tmptran[neidx]
            parentneid = tmptran[parentidx]
            childne = self.getnebysiteid(neid)
            parentne = self.getnebysiteid(parentneid)
            if childne is None and parentne is None:
                empty += 1
                continue
            elif childne is None or parentne is None:
                halfempty += 1
                if parentne is None:
                    childnename = childne.m_name
                    parentnename = parentneid

                    if childnename not in self.m_fatherdata:
                        self.m_fatherdata[childnename] = []
                    self.m_fatherdata[childnename].append(parentnename)
                continue
            else:
                nonempty += 1
            childnename = childne.m_name
            parentnename = parentne.m_name

            if childnename not in self.m_fatherdata:
                self.m_fatherdata[childnename] = []
            self.m_fatherdata[childnename].append(parentnename)

            if childnename not in self.m_topodict:
                self.m_topodict[childnename] = []
            if parentnename not in self.m_topodict:
                self.m_topodict[parentnename] = []
            if parentnename not in self.m_directtopo:
                self.m_directtopo[parentnename] = []
            self.m_topodict[childnename].append(parentnename)
            self.m_topodict[parentnename].append(childnename)
            self.m_directtopo[parentnename].append(childnename)
        print "empty:", empty
        print "halfempty:", halfempty
        print "nonempty:", nonempty
コード例 #4
0
def tongjilocation():
    filereader = FileReader("../1022.csv")
    attridx = filereader.getattridx("LOCATION")
    trandata = {}
    while True:
        tmptran = filereader.readtransection()
        if tmptran is None:
            break
        loc = tmptran[attridx]
        try:
            locinfo = loc.split(";")[1].split("/")
            targetloc = locinfo[0]
            if targetloc not in trandata:
                trandata[targetloc] = 0
            trandata[targetloc] += 1
        except:
            print loc
            # raw_input()

    valuelist = trandata.values()
    valuelist.sort()
    c = Counter(valuelist)
    keylist = c.keys()
    keylist.sort()
    for key in keylist:
        print key,"\t:\t",c[key]
        raw_input()
    raw_input()
    itemslist = trandata.items()
    itemslist.sort(key=lambda v:v[1],reverse=True)
    for key,value in itemslist:
        print key
        print value
        raw_input()
コード例 #5
0
def tongjidistype(fname, attrname):
    filereader = FileReader(fname)
    attridx = filereader.getattridx(attrname)
    trandata = {}
    while True:
        tmptran = filereader.readtransection()
        if tmptran is None:
            break
        summary = tmptran[attridx]
        if summary not in trandata:
            trandata[summary] = 0
        trandata[summary] += 1

    valuelist = trandata.values()
    valuelist.sort()
    c = Counter(valuelist)
    keylist = c.keys()
    keylist.sort()
    for key in keylist:
        print key, "\t:\t", c[key]

    itemslist = trandata.items()
    itemslist.sort(key=lambda v: v[1], reverse=True)
    # for key,value in itemslist:
    #     print key
    #     print value
    #     raw_input()

    # print valuelist
    # raw_input()
    print "========================================================"
    import pprint
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(trandata)
    print "length:", len(trandata)
コード例 #6
0
def printidentifier():
    filereader = FileReader("../1022.csv")
    identifieridx = filereader.getattridx("NEIDENTIFIER")
    while True:
        tmptran = filereader.readtransection()
        identifier = tmptran[identifieridx]
        if tmptran is None:
            filereader.close()
            break
        print identifier
        raw_input()
コード例 #7
0
def testwrongfile():
    filereader = FileReader("../wrongdocfile")
    alarmcodeidx = filereader.getattridx("ALARMCODE")
    attridx = filereader.getattridx("SUMMARY")
    locidx = filereader.getattridx("LOCATION")
    timeidx = filereader.getattridx("ALARMHAPPENTIME")
    print "idxdata:", timeidx, alarmcodeidx, locidx, attridx
    print filereader.m_header
    print filereader.m_headerlen
    while True:
        tmptran = filereader.readtransection()
        if tmptran is None:
            filereader.close()
            break

        summary = tmptran[attridx]
        location = tmptran[locidx]
        alarmcode = tmptran[alarmcodeidx]
        timestr = tmptran[timeidx]
        print tmptran
        raw_input()
コード例 #8
0
def tongjinetype():
    filereader = FileReader("../NE_INFO.csv")
    attridx = filereader.getattridx("NE_CAT_ID")
    trandata = {}
    while True:
        tmptran = filereader.readtransection()
        if tmptran is None:
            break
        summary = tmptran[attridx]
        if summary not in trandata:
            trandata[summary] = 0
        trandata[summary] += 1
    import pprint
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(trandata)
コード例 #9
0
def calneidlen():
    filereader = FileReader("../NE_INFO.csv")
    attridx = filereader.getattridx("NE_NO")
    lendict = {}
    idx = 0
    while True:
        tmptran = filereader.readtransection()
        if tmptran is None:
            break
        neid = tmptran[attridx]
        neidlen = len(neid)
        if neidlen not in lendict:
            lendict[neidlen] = 0
        lendict[neidlen] += 1
        idx += 1
        print neid
        if idx % 100 == 0:
            raw_input()
    import pprint
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(lendict)
コード例 #10
0
    def testfound(self):
        # fnamelist = ["../wrongdocfile",]
        # fnamelist = ["../10"+str(v)+".csv" for v in xrange(22,23)]
        # fnamelist = ["../1125.csv",]
        fnamelist = ["../10"+str(v)+".csv" for v in xrange(22,32)] + \
            ["../110"+str(v)+".csv" for v in xrange(01,10)] + \
            ["../11"+str(v)+".csv" for v in xrange(10,31)] + \
            ["../120"+str(v)+".csv" for v in xrange(01,10)] + \
            ["../12"+str(v)+".csv" for v in xrange(10,23)]
        cnt = 0
        found = 0
        wholeresult = {}
        writeflag = True
        if writeflag:
            writefile = open("../cleandata", "w")

        wrongdocflag = False

        if wrongdocflag:
            wrongdocfile = open("../wrongdocfile", "w")
            wrongdocfile.write(",".join([
                '"ALARMHAPPENTIME"', '"ALARMCODE"', '"LOCATION"', '"SUMMARY"'
            ]) + "\n")

        missloc = {}
        print "||||||||||||||||"
        fnamecnt = open("fnamecnt", "w")
        for fname in fnamelist:
            print fname
            filereader = FileReader(fname)
            alarmcodeidx = filereader.getattridx("ALARMCODE")
            attridx = filereader.getattridx("SUMMARY")
            locidx = filereader.getattridx("LOCATION")
            timeidx = filereader.getattridx("ALARMHAPPENTIME")
            identifieridx = filereader.getattridx("NEIDENTIFIER")
            cntidx = 0
            while True:
                tmptran = filereader.readtransection()
                cntidx += 1
                # print cntidx
                if tmptran is None:
                    filereader.close()
                    break

                summary = tmptran[attridx]
                location = tmptran[locidx]
                alarmcode = tmptran[alarmcodeidx]
                identifier = tmptran[identifieridx]
                warn = Warning(summary, location)
                if warn.m_type == NOTP4:
                    continue
                ftword = warn.getfirstword()
                if ftword not in wholeresult:
                    wholeresult[ftword] = {"cnt": 0, "good": 0}
                wholeresult[ftword]["cnt"] += 1
                cnt += 1
                loc = self.m_topo.getnebyidentifier(identifier)
                if loc is None:
                    loc = warn.fetchloc(self.m_topo)
                if loc is None:
                    locstr = warn.fetchlocstr()
                    if warn.m_type != NOTP5 and warn.m_type != TP9:
                        if locstr not in missloc:
                            missloc[locstr] = 0
                            print "==============================================="
                            print warn.m_summary
                            print "----------------------------------"
                            print warn.m_location
                            print "----------------------------------"
                            print identifier
                            print "locstr:", warn.m_type, locstr
                        missloc[locstr] += 1
                    if wrongdocflag:
                        wrongdocfile.write(",".join(['\"'+v+'\"' for v in \
                        [tmptran[timeidx],tmptran[alarmcodeidx],tmptran[locidx],tmptran[attridx],]])+"\r\n")
                    continue
                wholeresult[ftword]["good"] += 1
                found += 1
                summary = summary.replace("\n", "_")
                if writeflag:
                    writefile.write(alarmcode + "\t" + loc.m_name + "\t" +
                                    summary + "\t" + tmptran[timeidx] + "\n")
            print fname, "\t", cntidx
            fnamecnt.write(fname + "\t" + str(cntidx) + "\n")
        fnamecnt.close()
        if writeflag:
            writefile.close()
        if wrongdocflag:
            wrongdocfile.close()

        print "result:"
        print "cnt:", cnt
        print "found:", found
        print "pcg:", found * 1.0 / cnt

        for v in wholeresult.keys():
            if wholeresult[v]["good"] == wholeresult[v]["cnt"]:
                del wholeresult[v]
            else:
                wholeresult[v]["pcg"] = wholeresult[v][
                    "good"] * 1.0 / wholeresult[v]["cnt"]
        import pprint
        pprint.pprint(wholeresult)
        print "-----------------------"
        pprint.pprint(missloc)
        print "missloclen:", len(missloc)
        json.dump(wholeresult, open("tmpwholeresult", "w"))
        json.dump(missloc, open("missloc", "w"))