From 296c2ce840c0b9adbebd33899ce104450954667e Mon Sep 17 00:00:00 2001 From: edward Date: Mon, 6 Jun 2016 19:50:09 +0800 Subject: [PATCH] my first commit --- .DS_Store | Bin 0 -> 10244 bytes 1 | 1 + 1.txt | 41 ++ 2 | 104 ++++ 2.txt | 1 + 3 | 21 + 4 | 3 + Pool.pyc | Bin 0 -> 1301 bytes a.json | 21 + appdistribute.py | 858 ++++++++++++++++++++++++++++ appdistribute.pyc | Bin 0 -> 19608 bytes auau.py | 119 ++++ auidid.py | 167 ++++++ auidid.txt | 15 + bof.py | 226 ++++++++ calcHistogram.py | 22 + compare.py | 136 +++++ evaluate.py | 23 + final_14_21.py | 750 ++++++++++++++++++++++++ final_14_22.py | 750 ++++++++++++++++++++++++ final_14_22.pyc | Bin 0 -> 17771 bytes final_15_13.py | 750 ++++++++++++++++++++++++ final_15_13.pyc | Bin 0 -> 18043 bytes id-auid.py | 151 +++++ idid_idauid_auidid_auau - 副本.py | 690 ++++++++++++++++++++++ idid_idauid_auidid_auau.py | 750 ++++++++++++++++++++++++ idid_idauid_auidid_auau.pyc | Bin 0 -> 16784 bytes interpret.py | 22 + pool.py | 12 + rest.py | 16 + rest.pyc | Bin 0 -> 664 bytes root@45.62.110.239 | 750 ++++++++++++++++++++++++ test1 - 副本 (2).py | 708 +++++++++++++++++++++++ test1 - 副本 (3).py | 713 +++++++++++++++++++++++ test1 - 副本 (4).py | 732 ++++++++++++++++++++++++ test1 - 副本.py | 707 +++++++++++++++++++++++ test1 - 副本.pyc | Bin 0 -> 16599 bytes test1.py | 756 ++++++++++++++++++++++++ test1.pyc | Bin 0 -> 17826 bytes test1_idid.py | 713 +++++++++++++++++++++++ test1_idid_idauid.py | 663 +++++++++++++++++++++ test1_idid_idauid_auidid.py | 669 ++++++++++++++++++++++ test1_idid_idauid_auidid_auau.py | 675 ++++++++++++++++++++++ test1_idid_idauid_auidid_auau.pyc | Bin 0 -> 15889 bytes test1副本.py | 727 +++++++++++++++++++++++ test1副本.pyc | Bin 0 -> 12695 bytes 46 files changed, 13462 insertions(+) create mode 100644 .DS_Store create mode 100755 1 create mode 100755 1.txt create mode 100755 2 create mode 100644 2.txt create mode 100755 3 create mode 100755 4 create mode 100755 Pool.pyc create mode 100755 a.json create mode 100755 appdistribute.py create mode 100644 appdistribute.pyc create mode 100755 auau.py create mode 100755 auidid.py create mode 100755 auidid.txt create mode 100755 bof.py create mode 100755 calcHistogram.py create mode 100755 compare.py create mode 100755 evaluate.py create mode 100755 final_14_21.py create mode 100755 final_14_22.py create mode 100644 final_14_22.pyc create mode 100755 final_15_13.py create mode 100644 final_15_13.pyc create mode 100755 id-auid.py create mode 100755 idid_idauid_auidid_auau - 副本.py create mode 100755 idid_idauid_auidid_auau.py create mode 100755 idid_idauid_auidid_auau.pyc create mode 100755 interpret.py create mode 100755 pool.py create mode 100755 rest.py create mode 100755 rest.pyc create mode 100644 root@45.62.110.239 create mode 100755 test1 - 副本 (2).py create mode 100755 test1 - 副本 (3).py create mode 100755 test1 - 副本 (4).py create mode 100755 test1 - 副本.py create mode 100755 test1 - 副本.pyc create mode 100755 test1.py create mode 100755 test1.pyc create mode 100755 test1_idid.py create mode 100755 test1_idid_idauid.py create mode 100755 test1_idid_idauid_auidid.py create mode 100755 test1_idid_idauid_auidid_auau.py create mode 100755 test1_idid_idauid_auidid_auau.pyc create mode 100755 test1副本.py create mode 100755 test1副本.pyc diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c24ddddd9814b3a49aed0261a2b638ea6cb5bd70 GIT binary patch literal 10244 zcmeHM!BP`J5ba3A=lr;n7uE&R@&b}|UyMrAw$gt7F1Kjz0&z3gX2 zb5G*!hawcdcw#KM2x}RO(1`MQ`K(NXgOuJC;nNcEjl*xy4m=ESeC{|*X%{?h(}$ov z?-MO~8P#B!LU$h)2VvGFC%@wA(EB7_nYjzbN_m<`Mtd|AyDqA`OL#s*Jae_EsI#7xZO${|R@ODJ)u(0f zHI}nLuFO;EwHN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K- z?Dj==*C*R~>Q1g{?cYeQ3R 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError,IndexError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError,IndexError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError,IndexError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + params = urllib.urlencode({ + 'expr': "Composite(AA.AuN='"+input_data.id1+"')", + 'offset': '0', + 'count': '10', + 'attributes': 'AA.AuId,AA.AuN', + #'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + print(data) + conn.close() + AuId1=data6["entities"][0]["AA"] + for tmp in AuId1: + if tmp["AuN"]==input_data.id1: + input1 = tmp["AuId"]; + break; + + + params = urllib.urlencode({ + 'expr': "Composite(AA.AuN='"+input_data.id2+"')", + 'offset': '0', + 'count': '10', + 'attributes': 'AA.AuId,AA.AuN', + #'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params) + response = conn.getresponse() + data = response.read() + data7 = json.loads(data) + print(data) + conn.close() + AuId2=data7["entities"][0]["AA"] + for tmp in AuId2: + if tmp["AuN"]==input_data.id2: + input2 = tmp["AuId"]; + break; + + input=[input1,input2] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +class get_paper: + def GET(self,user): + input_data = web.input() + input = (int)(input_data.id) + exp9 = 'Id = %d' % input + params1 = urllib.urlencode({ + 'expr':exp9, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'Ti,Id,Y,CC,RId,F.FId,AA.AfId,AA.AuId,J.JId,C.CId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + print data + return data + + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError,IndexError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError,IndexError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError,IndexError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data3 > 120 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError,IndexError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError,IndexError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError,IndexError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError,IndexError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 120 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError,IndexError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + # AA.AuId -> AA.AfId(AA.AfN) -> AA.AuId + for x in AfId1: + if x in AfId2: + params = urllib.urlencode({ + # Request parameters + #'expr': "Composite(AA.AuN='kai chen')", + 'expr': "Composite(AA.AfId = %d)" % x, + #'expr': 'Id = 1970381522', + #'model': 'latest', + 'offset': '0', + #'orderby': 'AA.AfId', + 'count': '10', + 'attributes': 'Id,Ti,RId,F.FId,AA.AfId,AA.AfN,AA.AuN', + #'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params) + response = conn.getresponse() + data = response.read() + data8 = json.loads(data) + print(data) + conn.close() + AuId8=data8["entities"][0]["AA"] + for tmp in AuId8: + if tmp["AfId"]==x: + AuN8 = tmp["AfN"]; + break; + result.append([deinput[0],AuN8,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + params = urllib.urlencode({ + # Request parameters + 'expr': 'Id = %d' % x, + 'offset': '0', + 'attributes': 'Id,Ti,RId,F.FId,AA.AfId,AA.AfN,AA.AuN', + #'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params) + response = conn.getresponse() + data = response.read() + data9 = json.loads(data) + print(data) + conn.close() + result.append([deinput[0],data9["entities"][0]["Ti"],deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/appdistribute.pyc b/appdistribute.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a8f7292183d04651ae7be5d516e069d2cce8892a GIT binary patch literal 19608 zcmeHPTWlQHc|J3lAPb6g5x-1q#Ct$x|O%wC+Oz7p>cey8XWY z%?>dLzCq13g!#Cd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MnHJan0k+$d$~ZnBoC==x`-_IgMukbA@O6Ozyyij$GKy z++HRRGI@fD*a2t)uqkud-(>PE6KsXDvrHg*D|?j*_sHHvB0Ut=*UDQix!bUT%UV97 zo#&5n+!8n5kNu$UeYeqS#mzo5ZYH|re;3kYiCu{uiTjb>+jAlDVqz(ADRH&c_-~@m BFM0p~ literal 0 HcmV?d00001 diff --git a/auau.py b/auau.py new file mode 100755 index 0000000..37cad89 --- /dev/null +++ b/auau.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import httplib, urllib, base64 +import json + +result=[] +input = [2132060629,307743305] +encodeinput = json.dumps(input) +deinput = json.loads(encodeinput) +#''''''''''''''''''''''''''''''''''[AA.AuId, AA.AuId]''''''''''''''''''''''''''''''''' +#'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' +exp1 = "Composite(AA.AuId = %d )" % deinput[0] +params1 = urllib.urlencode({ + 'expr': exp1, + 'model': 'latest', + 'offset': '0', + 'count': '10000', + 'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data1 = json.loads(data) +conn.close() +#'''''''''''''''''''''''''2nd API''''''''''''''''''''''''''''''''' +exp2 = "Composite(AA.AuId = %d )" % deinput[1] +params1 = urllib.urlencode({ + 'expr':exp2, + 'count': '1000', + 'model': 'latest', + 'attributes': 'Id,AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data2 = json.loads(data) +conn.close() + +#'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' +AfId2=[] +for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue +Id2=[] +for id2 in data2["entities"]: + if id2["Id"] not in Id2: + Id2.append(id2["Id"]) + +#'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' +#print data1 +Id1=[] +AfId1=[] +for i1 in data1["entities"]: + Id1.append(i1["Id"]) +print Id1 +for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + +# AA.AuId -> AA.AfId -> AA.AuId +for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + +# AA.AuId -> Id -> AA.AuId +for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + +#'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' +for aaid1 in Id1: + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '10000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + + +deresult = json.dumps(result) +print deresult +print len(deresult) diff --git a/auidid.py b/auidid.py new file mode 100755 index 0000000..1cced3d --- /dev/null +++ b/auidid.py @@ -0,0 +1,167 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import httplib, urllib, base64 +import json + +result=[] +input = [2251253715, 2180737804] +encodeinput = json.dumps(input) +deinput = json.loads(encodeinput) +exp1 = "Composite(AA.AuId = %d )" % deinput[0] +params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '10000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data1 = json.loads(data) +conn.close() +#print data + +#'''''''''''''''''''''''''2nd API''''''''''''''''''''''''''''''''' +exp2 = 'Id = %d' % deinput[1] +params1 = urllib.urlencode({ + 'expr':exp2, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data2 = json.loads(data) +conn.close() +#print data2 + +#'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' +exp3 = 'RId = %d' % deinput[1] +params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '10000', + 'attributes': 'Id', + 'model': 'latest', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data3 = json.loads(data) +conn.close() + +#'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' +try: + FId2 = data2["entities"][0]["F"] +except (KeyError): + FId2 = [] +try: + AuId2= data2["entities"][0]["AA"] +except (KeyError): + AuId2=[] +try: + CJId2= data2["entities"][0]["J"]["JId"] +except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + +#'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' +Id1=[] +AfId1=[] +for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] +# AA.AuId -> AA.AfId -> AA.AuId -> Id +for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + +#'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' +Id3 = [] +for i3 in data3["entities"]: + Id3.append(i3["Id"]) + +#************************************************************need gevent +#''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' +for Aid in Id1: + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +deresult = json.dumps(result) +print deresult +print len(result) diff --git a/auidid.txt b/auidid.txt new file mode 100755 index 0000000..06f9600 --- /dev/null +++ b/auidid.txt @@ -0,0 +1,15 @@ +[[2251253715, 2180737804], [2251253715, 2180737804, 2048498903, 2180737804], [2251253715, 2180737804, 2223920688, 2180737804], [2251253715, 2180737804, 949266530, 2180737804], [2251253715, 2180737804, 1783833040, 2180737804], [2251253715, 2180737804, 2251253715, 2180737804], [2251253715, 2180737804, 2108096461, 2180737804], [2251253715, 2180737804, 35927321, 2180737804], [2251253715, 2299839756, 2048498903, 2180737804], [2251253715, 2299839756, 949266530, 2180737804], [2251253715, 2299839756, 2223920688, 2180737804], [2251253715, 2299839756, 1783833040, 2180737804], [2251253715, 2299839756, 2251253715, 2180737804], [2251253715, 2299839756, 2108096461, 2180737804]] +Total Size: 14 + +2251253715 +2273736245 + + + + + + + + +2180737804 +2094437628 \ No newline at end of file diff --git a/bof.py b/bof.py new file mode 100755 index 0000000..1fa371f --- /dev/null +++ b/bof.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import httplib, urllib, base64 +import json + +result=[] +#input = [2157025439,2139398774] +input = [1970381522,2162351023] +encodeinput = json.dumps(input) +deinput = json.loads(encodeinput) +#''''''''''''''''''''''''''''''''''[id0, id1]''''''''''''''''''''''''''''''''' +#'''''''''''''''1st API'''''''''''''''''''''''' +exp1 = 'Id = %d' % deinput[0] +params1 = urllib.urlencode({ + 'expr':exp1, + 'model': 'latest', + 'offset': '0', + 'count': '10000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data1 = json.loads(data) +conn.close() + +#'''''''''''''''2nd API'''''''''''''''''''''''' +exp2 = 'Id = %d' % deinput[1] +params1 = urllib.urlencode({ + 'expr':exp2, + 'count': '10000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data2 = json.loads(data) +conn.close() + +#'''''''''''''''3rd API'''''''''''''''''''''''' +exp3 = 'RId = %d' % deinput[1] +params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '10000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) +response = conn.getresponse() +data = response.read() +data3 = json.loads(data) +conn.close() + +#''''''''''''''''''data 1''''''''''''''''''''''''''' +try: + ReId1=data1["entities"][0]["RId"] +except (KeyError): + ReId1 = [] +try: + FId1 = data1["entities"][0]["F"] +except (KeyError): + FId1 = [] +try: + AuId1= data1["entities"][0]["AA"] +except (KeyError): + AuId1=[] +try: + CJId1= data1["entities"][0]["J"]["JId"] +except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + +#''''''''''''''''''data 2''''''''''''''''''''''''''' +try: + FId2 = data2["entities"][0]["F"] +except (KeyError): + FId2 = [] +try: + AuId2= data2["entities"][0]["AA"] +except (KeyError): + AuId2=[] +try: + CJId2= data2["entities"][0]["J"]["JId"] +except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + +#''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w +Id3 = [] +FId3 = [] +AuId3 = [] +CJId3 = [] +for i in data3["entities"]: +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + continue +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + continue +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([[deinput[0],CJId3,i["Id"],deinput[1]]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([[deinput[0],CJId3,i["Id"],deinput[1]]]) + except(KeyError): + continue + +#''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' +#id -> id +for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break +#id -> id -> id +'''for Id in Id3: + for Reid in ReId1: + if Reid == Id: + result.append([deinput[0],Reid,deinput[1]])''' +#id -> F.FId -> id +for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) +#id -> AA.AuId -> id +for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) +#id -> C.CId/J.JId -> id +if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + +#''''''''''''''''''''4th API''''''''''''''''''''''''''''' +#id -> id -> XXXXXX -> id ************************************************************need gevent +for Reid in ReId1: + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +deresult = json.dumps(result) +print deresult +print len(result) diff --git a/calcHistogram.py b/calcHistogram.py new file mode 100755 index 0000000..476028a --- /dev/null +++ b/calcHistogram.py @@ -0,0 +1,22 @@ +import httplib, urllib, base64 + +params = urllib.urlencode({ + # Request parameters + 'expr': "Composite(AA.AuId = 621499171)", + 'model': 'latest', + 'count': '1000000', + 'offset': '0', + 'attributes': 'Ti,Id,Y,CC,RId,F.FId,AA.AfId,AA.AuId,J.JId,C.CId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) + +try: + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/calchistogram?%s" % params) + #conn.request("GET", "/academic/v1.0/evaluate?%s" % params, "{body}") + response = conn.getresponse() + data = response.read() + print(data) + conn.close() +except Exception as e: + print("[Errno {0}] {1}".format(e.errno, e.strerror)) diff --git a/compare.py b/compare.py new file mode 100755 index 0000000..31f5746 --- /dev/null +++ b/compare.py @@ -0,0 +1,136 @@ +import web +import httplib, urllib, base64 +import json + +mydata = [[2088905367, 2033660646], [2088905367, 2159929956, 2033660646], [2088905367, 2069656492, 2159929956, 2033660646], [2088905367, 2033660646, 2159929956, 2033660646], [2088905367, 1274808907, 2159929956, 2033660646], [2088905367, 53811970, 2159929956, 2033660646], [2088905367, 50231774, 2159929956, 2033660646], [2088905367, 529278444, 2159929956, 2033660646], [2088905367, 2131181615, 2033660646], [2088905367, 1274808907, 2131181615, 2033660646], [2088905367, 2033660646, 2131181615, 2033660646], [2088905367, 2069656492, 2131181615, 2033660646], [2088905367, 50231774, 2131181615, 2033660646], [2088905367, 1850231759, 2033660646], [2088905367, 1274808907, 1850231759, 2033660646], [2088905367, 2033660646, 1850231759, 2033660646], [2088905367, 2069656492, 1850231759, 2033660646], [2088905367, 2069656492, 2101328227, 2033660646], [2088905367, 1274808907, 2101328227, 2033660646], [2088905367, 2033660646, 2101328227, 2033660646], [2088905367, 2033660646, 2105947467, 2033660646], [2088905367, 2069656492, 2154282155, 2033660646], [2088905367, 2033660646, 2154282155, 2033660646], [2088905367, 1274808907, 2154282155, 2033660646], [2088905367, 169760540, 2154282155, 2033660646], [2088905367, 2335369236, 2088905367, 2033660646], [2088905367, 2043738800, 2088905367, 2033660646], [2088905367, 2069656492, 2088905367, 2033660646], [2088905367, 2033660646, 2088905367, 2033660646], [2088905367, 1274808907, 2088905367, 2033660646], [2088905367, 53811970, 2088905367, 2033660646], [2088905367, 50231774, 2088905367, 2033660646], [2088905367, 529278444, 2088905367, 2033660646], [2088905367, 105976826, 2088905367, 2033660646], [2088905367, 500300565, 2088905367, 2033660646], [2088905367, 169760540, 2088905367, 2033660646], [2088905367, 86033158, 2088905367, 2033660646], [2088905367, 2033660646, 2122609459, 2033660646], [2088905367, 1274808907, 2122609459, 2033660646], [2088905367, 2069656492, 2122609459, 2033660646], [2088905367, 169760540, 2122609459, 2033660646], [2088905367, 2033660646, 2154600934, 2033660646], [2088905367, 2069656492, 2154600934, 2033660646], [2088905367, 2033660646, 1994140286, 2033660646], [2088905367, 2033660646, 2134737825, 2033660646], [2088905367, 2069656492, 2128929670, 2033660646], [2088905367, 2033660646, 2128929670, 2033660646], [2088905367, 169760540, 2128929670, 2033660646], [2088905367, 2033660646, 2128912989, 2033660646], [2088905367, 2033660646, 2003904948, 2033660646], [2088905367, 2033660646, 1984589372, 2033660646], [2088905367, 2069656492, 1984589372, 2033660646], [2088905367, 2033660646, 2030985472, 2033660646], [2088905367, 529278444, 2030985472, 2033660646], [2088905367, 2069656492, 2137041983, 2033660646], [2088905367, 2033660646, 2137041983, 2033660646], [2088905367, 50231774, 2137041983, 2033660646], [2088905367, 2033660646, 1883022817, 2033660646], [2088905367, 2033660646, 2170961150, 2033660646], [2088905367, 2069656492, 2170961150, 2033660646], [2088905367, 2033660646, 2247633931, 2033660646], [2088905367, 2033660646, 2031787306, 2033660646], [2088905367, 2069656492, 2031787306, 2033660646], [2088905367, 169760540, 2031787306, 2033660646], [2088905367, 2033660646, 2162704817, 2033660646], [2088905367, 2069656492, 2162704817, 2033660646], [2088905367, 2033660646, 1794932940, 2033660646], [2088905367, 2069656492, 1794932940, 2033660646], [2088905367, 2033660646, 1494774730, 2033660646], [2088905367, 2069656492, 1494774730, 2033660646], [2088905367, 2033660646, 192442251, 2033660646], [2088905367, 2069656492, 192442251, 2033660646], [2088905367, 2033660646, 1975363664, 2033660646], [2088905367, 2033660646, 2014570568, 2033660646], [2088905367, 1274808907, 2014570568, 2033660646], [2088905367, 2069656492, 2014570568, 2033660646], [2088905367, 2033660646, 1597272258, 2033660646], [2088905367, 2033660646, 2091443859, 2033660646], [2088905367, 2033660646, 1657756828, 2033660646], [2088905367, 2033660646, 1992812931, 2033660646], [2088905367, 2069656492, 1992812931, 2033660646], [2088905367, 2033660646, 2009967614, 2033660646], [2088905367, 2069656492, 2009967614, 2033660646], [2088905367, 2033660646, 2248364736, 2033660646], [2088905367, 2069656492, 2248364736, 2033660646], [2088905367, 2033660646, 1784346353, 2033660646], [2088905367, 2033660646, 2243488354, 2033660646], [2088905367, 2069656492, 2243488354, 2033660646], [2088905367, 2069656492, 560994262, 2033660646], [2088905367, 2033660646, 560994262, 2033660646], [2088905367, 2033660646, 2176977794, 2033660646], [2088905367, 1274808907, 2176977794, 2033660646], [2088905367, 2069656492, 2176977794, 2033660646], [2088905367, 2033660646, 1523184210, 2033660646], [2088905367, 2069656492, 1523184210, 2033660646], [2088905367, 2033660646, 179882140, 2033660646], [2088905367, 2033660646, 106454395, 2033660646], [2088905367, 2033660646, 1818868717, 2033660646], [2088905367, 1274808907, 1818868717, 2033660646], [2088905367, 2069656492, 1608327386, 2033660646], [2088905367, 2033660646, 1608327386, 2033660646], [2088905367, 2033660646, 1966900795, 2033660646], [2088905367, 2069656492, 1966900795, 2033660646], [2088905367, 2033660646, 2245697195, 2033660646], [2088905367, 2033660646, 2244767582, 2033660646], [2088905367, 2033660646, 2247096175, 2033660646], [2088905367, 2033660646, 1756397654, 2033660646], [2088905367, 2033660646, 1657311722, 2033660646], [2088905367, 2033660646, 2247936397, 2033660646], [2088905367, 2069656492, 97565354, 2033660646], [2088905367, 2069656492, 5124864, 2033660646], [2088905367, 2033660646, 5124864, 2033660646], [2088905367, 2033660646, 142476485, 2033660646], [2088905367, 2033660646, 97565354, 2033660646], [2088905367, 1850231759, 2159929956, 2033660646]] + + +rightdata = [[2088905367,2033660646], +[2088905367,2159929956,2033660646], +[2088905367,2131181615,2033660646], +[2088905367,1850231759,2033660646], +[2088905367,2335369236,2088905367,2033660646], +[2088905367,2054825456,2088905367,2033660646], +[2088905367,2069656492,2088905367,2033660646], +[2088905367,2033660646,2088905367,2033660646], +[2088905367,1274808907,2088905367,2033660646], +[2088905367,86033158,2088905367,2033660646], +[2088905367,53811970,2088905367,2033660646], +[2088905367,50231774,2088905367,2033660646], +[2088905367,529278444,2088905367,2033660646], +[2088905367,105976826,2088905367,2033660646], +[2088905367,500300565,2088905367,2033660646], +[2088905367,169760540,2088905367,2033660646], +[2088905367,2069656492,2159929956,2033660646], +[2088905367,2033660646,2159929956,2033660646], +[2088905367,1274808907,2159929956,2033660646], +[2088905367,1850231759,2159929956,2033660646], +[2088905367,53811970,2159929956,2033660646], +[2088905367,50231774,2159929956,2033660646], +[2088905367,529278444,2159929956,2033660646], +[2088905367,2069656492,2131181615,2033660646], +[2088905367,2033660646,2131181615,2033660646], +[2088905367,1274808907,2131181615,2033660646], +[2088905367,50231774,2131181615,2033660646], +[2088905367,2069656492,1850231759,2033660646], +[2088905367,2033660646,1850231759,2033660646], +[2088905367,1274808907,1850231759,2033660646], +[2088905367,2069656492,5124864,2033660646], +[2088905367,2033660646,5124864,2033660646], +[2088905367,2069656492,2101328227,2033660646], +[2088905367,2033660646,2101328227,2033660646], +[2088905367,1274808907,2101328227,2033660646], +[2088905367,2033660646,2105947467,2033660646], +[2088905367,2033660646,142476485,2033660646], +[2088905367,2069656492,2154282155,2033660646], +[2088905367,2033660646,2154282155,2033660646], +[2088905367,1274808907,2154282155,2033660646], +[2088905367,169760540,2154282155,2033660646], +[2088905367,2069656492,2122609459,2033660646], +[2088905367,2033660646,2122609459,2033660646], +[2088905367,1274808907,2122609459,2033660646], +[2088905367,169760540,2122609459,2033660646], +[2088905367,2069656492,2154600934,2033660646], +[2088905367,2033660646,2154600934,2033660646], +[2088905367,2033660646,1994140286,2033660646], +[2088905367,2033660646,2134737825,2033660646], +[2088905367,2069656492,2128929670,2033660646], +[2088905367,2033660646,2128929670,2033660646], +[2088905367,169760540,2128929670,2033660646], +[2088905367,2033660646,2128912989,2033660646], +[2088905367,2069656492,1984589372,2033660646], +[2088905367,2033660646,1984589372,2033660646], +[2088905367,2033660646,2030985472,2033660646], +[2088905367,529278444,2030985472,2033660646], +[2088905367,2033660646,2003904948,2033660646], +[2088905367,2033660646,1883022817,2033660646], +[2088905367,2069656492,2137041983,2033660646], +[2088905367,2033660646,2137041983,2033660646], +[2088905367,50231774,2137041983,2033660646], +[2088905367,2069656492,2170961150,2033660646], +[2088905367,2033660646,2170961150,2033660646], +[2088905367,2033660646,2247633931,2033660646], +[2088905367,2069656492,2162704817,2033660646], +[2088905367,2033660646,2162704817,2033660646], +[2088905367,2069656492,2031787306,2033660646], +[2088905367,2033660646,2031787306,2033660646], +[2088905367,169760540,2031787306,2033660646], +[2088905367,2069656492,97565354,2033660646], +[2088905367,2033660646,97565354,2033660646], +[2088905367,2069656492,1794932940,2033660646], +[2088905367,2033660646,1794932940,2033660646], +[2088905367,2069656492,1494774730,2033660646], +[2088905367,2033660646,1494774730,2033660646], +[2088905367,2069656492,192442251,2033660646], +[2088905367,2033660646,192442251,2033660646], +[2088905367,2033660646,1975363664,2033660646], +[2088905367,2069656492,2014570568,2033660646], +[2088905367,2033660646,2014570568,2033660646], +[2088905367,1274808907,2014570568,2033660646], +[2088905367,2033660646,2091443859,2033660646], +[2088905367,2033660646,1657756828,2033660646], +[2088905367,2033660646,1597272258,2033660646], +[2088905367,2069656492,1992812931,2033660646], +[2088905367,2033660646,1992812931,2033660646], +[2088905367,2069656492,2009967614,2033660646], +[2088905367,2033660646,2009967614,2033660646], +[2088905367,2069656492,2248364736,2033660646], +[2088905367,2033660646,2248364736,2033660646], +[2088905367,2069656492,2243488354,2033660646], +[2088905367,2033660646,2243488354,2033660646], +[2088905367,2033660646,1784346353,2033660646], +[2088905367,2069656492,560994262,2033660646], +[2088905367,2033660646,560994262,2033660646], +[2088905367,2069656492,1523184210,2033660646], +[2088905367,2033660646,1523184210,2033660646], +[2088905367,2033660646,179882140,2033660646], +[2088905367,2069656492,2176977794,2033660646], +[2088905367,2033660646,2176977794,2033660646], +[2088905367,1274808907,2176977794,2033660646], +[2088905367,2033660646,1818868717,2033660646], +[2088905367,1274808907,1818868717,2033660646], +[2088905367,2033660646,106454395,2033660646], +[2088905367,2033660646,2339875128,2033660646], +[2088905367,2069656492,1966900795,2033660646], +[2088905367,2033660646,1966900795,2033660646], +[2088905367,2033660646,2245697195,2033660646], +[2088905367,2069656492,1608327386,2033660646], +[2088905367,2033660646,1608327386,2033660646], +[2088905367,2033660646,2244767582,2033660646], +[2088905367,2033660646,2247096175,2033660646], +[2088905367,2033660646,1756397654,2033660646], +[2088905367,2033660646,2247936397,2033660646], +[2088905367,2033660646,1657311722,2033660646]] + +print 'My extra data' +for x in mydata: + if x not in rightdata: + print x + +print "other's extra data" +for y in rightdata: + if y not in mydata: + print y + + + \ No newline at end of file diff --git a/evaluate.py b/evaluate.py new file mode 100755 index 0000000..fb72b5f --- /dev/null +++ b/evaluate.py @@ -0,0 +1,23 @@ +import httplib, urllib, base64 +import json +params = urllib.urlencode({ + # Request parameters + #'expr': "Composite(AA.AuN='kai chen')", + 'expr': "Composite(AA.AfId = 63021997)", + #'expr': 'Id = 1970381522', + #'model': 'latest', + 'offset': '0', + #'orderby': 'AA.AfId', + 'count': '10', + 'attributes': 'Id,Ti,RId,F.FId,AA.AfId,AA.AfN,AA.AuN', + #'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', +}) + +conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') +conn.request("GET", "/academic/v1.0/evaluate?%s" % params) +response = conn.getresponse() +data = response.read() +data1 = json.loads(data) +print(data) +conn.close() diff --git a/final_14_21.py b/final_14_21.py new file mode 100755 index 0000000..0e58b30 --- /dev/null +++ b/final_14_21.py @@ -0,0 +1,750 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web,time +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + #'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 180: + print "4th api > 180 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data3 > 150 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 150 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/final_14_22.py b/final_14_22.py new file mode 100755 index 0000000..9602306 --- /dev/null +++ b/final_14_22.py @@ -0,0 +1,750 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web,time +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + #'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data3 > 120 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 120 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/final_14_22.pyc b/final_14_22.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0c11874a083d053e64556cbb4b5a3454040f5bd3 GIT binary patch literal 17771 zcmeHPTWlQHc|J3{TylB8i6UiNrY##;#TF@EE!&AKS&T@^4nYs)E<=Z4mYkuq)N*%c zXJ{>B(k-mO$wOb#B28Y>qG?`?0%@L$0CiCyXix(M`p}o6s8JLsoQI;W3&b$cxZn4m zncdloY|*ls+AXOVi3-crF&4A%?zde0k5+4vYLr_`>Y z)(o|4sx?y?j-hs9>XuRl%T1QAXeG5JIC_5pUUS+pRrcc>zlId4=QZfU| zZkNoUvO6SmOxc~18B%taWR5GlTQbAS?vc!hvM~ib@8vCe|JvFKW%o(heah~a%>Bw9 zkjw+h9+b>U*_wv|fq(Mh=-NyZ;u}es=j9po@{dN#%e7}_4++*9LxZQqY zYish!nX^x3&P`8GZOv>>WoDe2+0C=g)Va->%&gZ7B5!Zg+bU&?ezuT5gZJkR;bEb? zT`1YtZ;WNWxmR+|WQy6bJcb@a(fn7gdM9ul&unFEXE(bw{_@1w*>UIPOl}Xedgf6t z)q!G}(OxN+%WnEf+#~Dcw=h?~6?fNtzsQmvo2sYRSpidXaL4;L(nUdfa!pLdNzaXJ`D(M2g!>8nm5kzPRUyuVq3W7Bi*H zt~VhMw=e+No;7{36}|-}iT5~i<1b?GdgG3LGlLZ>l#1hXj(5W^6uHsIx3l?7ZewD4 zV{&q=xGybZ@g}%yy!+XZ*=;0^*2-^}*<%bEo%n4xKDP`(7O=Q?EWSUBFUsPZvA7j1 z$^?sBxk-y$W8KGuJHdJY$)~WlCQqTAPq4RsfND*JEhON_3)>ng3s8$n*)Gc6kCU=s zz@4^GwnE547`Kbi6)DU0Uh=p-0vcf^(CYjxsN4x^=m$t+YM5f7 zRUN>HGSrQ@DoxM~n_nOh*ihY-8aiwvj6z$_Lf$~>k3-vsEtbFqw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>suD#UcE66?-3Xr> zsQ+gaKAXr?^xQgqRcokK(a{01P%nTQXyB3QG#(AoK&Ti&U}-m#&2MbT|C?y|&k|l6 z1`_^f2|cxk@WhfOe?Zb(sIV zz>`oN{yrp^-4b^pwjMgn6*e;{qnJaPHgit0E$RFb=Dxs0LXqMr6yt_=jYZ_K1c>Bq zV>y+$(JWdK7UjFeb+&FIkseBW`RYrP+>tF5S;;Typxk+mS`OI_!Iof5?-8RjmN1W* i2{YL*zkNubNj{uBnS2oG{R5|yzn$DpzLY%QY5X^&L)sJo literal 0 HcmV?d00001 diff --git a/final_15_13.py b/final_15_13.py new file mode 100755 index 0000000..933409d --- /dev/null +++ b/final_15_13.py @@ -0,0 +1,750 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web,time +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + #'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError,IndexError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError,IndexError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError,IndexError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError,IndexError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError,IndexError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError,IndexError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data3 > 120 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError,IndexError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError,IndexError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError,IndexError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError,IndexError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 120 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError,IndexError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/final_15_13.pyc b/final_15_13.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6616d1d8b1c876cdcbd859983c332b9bafbc8e8e GIT binary patch literal 18043 zcmeHPTWlQHc|J3HA(wYjyoj=KY>5)Nq$FQrix#6>Y}OtsUWzhHFF8YLDROsb zXK1ei(rGFO2~zvPFNNU%PSWHhKn(+ZXyG;moc6^){ZtrzXrB7e7IlFZaM8MbsN3)R z&&=-Za%oGZ)zogu-7{zAob#W{od5s+%OPX`(%JTX^JI2e1wS!dPvPr5X((mmW2iNy z)(tgpsC84#o62wuwHi}5lrmUuvV30GMLw?P9l-(tny~^&E%&@XC1w8NJEqcE+zfak{Qg(;3`y_Lx zviC^lE@k&iX1{XoR`!6pW~%Zz!|7D3BeF;ZS)|$YUaV^Vzwnbbk@J&C){BK}&UHV* z^qv?73u!ZlL(KAScj^w(6`_rSRkzN?RaNhRYP&w!O<^0kHX^-G` z<;3#x_(PM&9?G4Zn8++oE@g6)&gAi>V@~Ge(q!(q*Mmyl#*(*O&X@drv2X>SCJ@}mU|J%*yQU%%+>!}VxxIcGcT`Q@W8jEx>U>b#I!+rX?I zKj@{~Q7kjsD6g&Mm;4m&k#!2on5*A{yQ{umVo5jh=Pq7+diHd&P;izx1}QH)?gkf# zl(1jQj#nxcuy|b6vXis*BCQpJN2?y%ao?>KbG9crJLl)d(%fD`(01~L(uN$nP72?+|quxxZf@Ak6Ycv7Nye7Y+J`+_*)qvF>2PonYOC<^<63SPlM(Uwzht{?-zgKa zg|=^(iQBYYCMK~|vil>V$ZRocf~dQRAbJgrnr;?A=cjCzx?O_T8{H-C)LnMBOUR$~ zyQC&*s=LG+My-1I{4(r|$sP8^iHroT}+3HYGI9DN+G@x}#(@sI9>w{`j zaBUby#4xOg;jJ!}E!?HzewTt8yJD(qZL0jw$}o&8m|vGF7;3J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yPKN$w*s2C#kya3i63}i2V1Lb) zf$<&o5=s&R*sns$0I**v0Wh*$t6)w_RsO`}Nf5N0UU=Jt{arIofj=-#kp{*oI1wTG zHo=@j2CVx4bHM5lOE|3pn4{1Ove;W8B(4e6Xd@D97nB5$2-!u+kM=-I7|^s%JGJER z5}*krKOC_*L5KK0@dg));8z<6>p=t+!fpb=^Qz&#YGmEtGMb3uf5jSB?PL()Yl7j9 zk?@EwFi4LifIN&uPWKFRK#2BpBtsE9nNzHdL>~v>QiKNqhD>(|7}VAbgT7t0*q@OD z%)t?3jj{nL&}WxFFgXl51vLJ=ZxVm7%KE9spZ87o2mCad^oP~1fIk>-xXa+b#z*7N zv4|lYnHI|R+YP29`14VN^Wn$DHyXmA9qz~|?N@Gr_D@JlLxua3*qr+jjv{`f1b_OX z_yefut2gE}c+~Lc4`Lzy^i}Z(E|GghV-z+RqFV$G5-z3uv9#=J_djBh?r6#atKcz- zb_Wi@6JS+;748mHu}XIbIUD>va06Cp_ihBMA^`QNrefZP=<-4XQE-UiGcgb~ZqZ8A z=Ov#)t|=njgh}`usR$y?kqQN-MkL7*EVOYb*wkR_5rT9~`1{N~!Gs2f2B2!J*V^K< z8XjHZE$u`d6V4*H8)RBT`-=cV?{#Dp%pjO^O)x2fMX1w=K>f!4Cb-jxL&UJ~pyCcV z1XL6pLLa@xKn;yz7#kyHE%=I2_A-Wyt)BzO8G*$R6X_jSmG^7g_FX!cVKcA7!29;1-4{Lk;*{`IAh525RD|mO$?+_a%OCtoR;C2#lyDjAi`|u?bJ{nZsB3OGoE$ z(iu|=feBNC>GK&=)4((l0VWtj7z;2fGBwEluj>X!b8(oF&vtHPXG*LwOIkt%^a3D zG{D|7-1lIBp*6j9)z%2Qp>aX_GQE$v`!Z19MLYa2u0R& zOrB?g AA.AuId (1-hop) + +#'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' +print ("Data1") +print data1 + +AfId1=[] +Id1=[] +for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + continue + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + +for tmp in AfId1: + for x in AuId2: + if tmp == x["AfId"]: + # Id -> AA.AuId -> AA.AfId -> AA.AuId (3-hop) + result.append([deinput[0],x["AuId"],tmp,deinput[1]]) + +#************************************************************need gevent +#''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' +for rid in ReId2: + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) +print ("Data4") +print data4 + +deresult = json.dumps(result) +print ("Result") +print deresult +#print len(deresult) diff --git a/idid_idauid_auidid_auau - 副本.py b/idid_idauid_auidid_auau - 副本.py new file mode 100755 index 0000000..c5910cf --- /dev/null +++ b/idid_idauid_auidid_auau - 副本.py @@ -0,0 +1,690 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + #for Id in Id3: + #if rid == Id: + #result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + #for y in AfId1: + #if x == y : + #result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + #for tmp in Id1: + #if rid4 == tmp: + #result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + #for tmp in Id3: + #if rid == tmp: + #result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + #for y in Id2: + #if x==y: + #result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + #for y in AfId2: + #if x==y: + #result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + #for y in Id2: + #if x==y: + #result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/idid_idauid_auidid_auau.py b/idid_idauid_auidid_auau.py new file mode 100755 index 0000000..933409d --- /dev/null +++ b/idid_idauid_auidid_auau.py @@ -0,0 +1,750 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web,time +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + #'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError,IndexError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError,IndexError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError,IndexError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError,IndexError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError,IndexError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError,IndexError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError,IndexError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data3 > 120 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError,IndexError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError,IndexError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError,IndexError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError,IndexError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError,IndexError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 120 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError,IndexError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError,IndexError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError,IndexError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError,IndexError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError,IndexError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError,IndexError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError,IndexError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/idid_idauid_auidid_auau.pyc b/idid_idauid_auidid_auau.pyc new file mode 100755 index 0000000000000000000000000000000000000000..4e7566991ac9043f89a3c78d6db22987ca439762 GIT binary patch literal 16784 zcmeHOTWlQHc|J3HA(!OxCW<0uTcR&&R<%WmSIbsxNfs@VvP(!K$IDV7m?d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000000..9602306 --- /dev/null +++ b/root@45.62.110.239 @@ -0,0 +1,750 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web,time +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + #'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + #'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + #'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Reid,rid,deinput[1]]) + + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId2: + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "3th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + if x in AfId1: + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + if rid4 in Id1: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "4th api > 150 s" + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + if rid in Id3: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auidid5api(auid2,deinput,AfId1): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 135: + print "5th api > 150 s" + return + exp3 = "Composite(AA.AuId = %d )" % auid2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data6 = json.loads(data) + conn.close() + AfId2=[] + for i3 in data6["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == auid2["AuId"]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId2: + if x in AfId1: + result.append([deinput[0],auid2["AuId"],x,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 150: + print "data1 > 100 s" + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + if x in Id2: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + global start_time + start_time = time.clock() + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + #print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + print "data2" + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "data3" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data3 > 120 s" + break + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + print "operation" + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1: + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "data4" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 120: + print "data1 > 120 s" + break + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + threads=[] + for auid2 in AuId2: + threads.append(gevent.spawn(auidid5api,auid2,deinput,AfId1)) + gevent.joinall(threads) + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + Id2=[] + for id2 in data2["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 100: + print "data2 > 100 s" + break + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + now = time.clock() + exe_time = (float)(now - start_time) + if exe_time > 130: + print "data1 > 100 s" + break + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + if x in AfId2: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + if x in Id2: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1 - 副本 (2).py b/test1 - 副本 (2).py new file mode 100755 index 0000000..4f7a78e --- /dev/null +++ b/test1 - 副本 (2).py @@ -0,0 +1,708 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json +import time +from multiprocessing.dummy import Pool as ThreadPool + + + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '1000000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '1000000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +def ididfor(i): + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([xxinput[0],tmp["FId"],i["Id"],xxinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([xxinput[0],tmp["AuId"],i["Id"],xxinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + pass + +def idauidfor(i1): + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([xxinput[0],i1["Id"],xxinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([xxinput[0],x["AuId"],i1["Id"],xxinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([xxinput[0],x["FId"],i1["Id"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == xxinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except: + CJId1=[] + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + + +def idid(deinput,data4,data5,data3): + global result,start_time,xxinput,FId1,AuId1,CJId1,Id3 + start_time = time.clock() + xxinput=deinput + result=[] + Id3=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + pool = ThreadPool(4) + pool.map(ididfor,data3["entities"]) + pool.close() + pool.join() + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result,start_time,ReId2,xxinput,AuId2,FId2,CJId2,Id1,AfId1 + Id1=[] + AfId1=[] + start_time = time.clock() + xxinput=deinput + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(idauidfor,data1["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result,start_time + result=[] + start_time = time.clock() + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result,start_time + result=[] + start_time = time.clock() + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1 - 副本 (3).py b/test1 - 副本 (3).py new file mode 100755 index 0000000..a97b5ee --- /dev/null +++ b/test1 - 副本 (3).py @@ -0,0 +1,713 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json +import time +from multiprocessing.dummy import Pool as ThreadPool + + + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '1000000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '1000000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +def ididfor(i): + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([xxinput[0],tmp["FId"],i["Id"],xxinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([xxinput[0],tmp["AuId"],i["Id"],xxinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + pass + +def idauidfor(i1): + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([xxinput[0],i1["Id"],xxinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([xxinput[0],x["AuId"],i1["Id"],xxinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([xxinput[0],x["FId"],i1["Id"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == xxinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except: + CJId1=[] + +def auididfor(i1): + Id1.append(i1["Id"]) + if i1["Id"]==xxinput[1]: + result.append([xxinput[0],xxinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([xxinput[0],i1["Id"],tmp["FId"],xxinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([xxinput[0],i1["Id"],tmp["AuId"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==xxinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except: + CJId1=[] + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + + +def idid(deinput,data4,data5,data3): + global result,start_time,xxinput,FId1,AuId1,CJId1,Id3 + start_time = time.clock() + xxinput=deinput + result=[] + Id3=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + pool = ThreadPool(4) + pool.map(ididfor,data3["entities"]) + pool.close() + pool.join() + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result,start_time,ReId2,xxinput,AuId2,FId2,CJId2,Id1,AfId1 + Id1=[] + AfId1=[] + start_time = time.clock() + xxinput=deinput + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(idauidfor,data1["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result,start_time,Id1,AfId1,xxinput,FId2,AuId2,CJId2 + result=[] + Id1=[] + AfId1=[] + xxinput = deinput + start_time = time.clock() + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(auididfor,data1["entities"]) + pool.close() + pool.join() + + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result,start_time + result=[] + start_time = time.clock() + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1 - 副本 (4).py b/test1 - 副本 (4).py new file mode 100755 index 0000000..24d5b77 --- /dev/null +++ b/test1 - 副本 (4).py @@ -0,0 +1,732 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json +import time +from multiprocessing.dummy import Pool as ThreadPool + + + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '1000000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + print ">200" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4 = data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + print "Reid" + print Reid + print ReId4 + print "deinput" + print deinput + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '1000000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +def ididfor(i): + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([xxinput[0],tmp["FId"],i["Id"],xxinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([xxinput[0],tmp["AuId"],i["Id"],xxinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + pass + +def idauidfor(i1): + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([xxinput[0],i1["Id"],xxinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([xxinput[0],x["AuId"],i1["Id"],xxinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([xxinput[0],x["FId"],i1["Id"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == xxinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except: + CJId1=[] + +def auididfor(i1): + Id1.append(i1["Id"]) + if i1["Id"]==xxinput[1]: + result.append([xxinput[0],xxinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([xxinput[0],i1["Id"],tmp["FId"],xxinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([xxinput[0],i1["Id"],tmp["AuId"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==xxinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except: + CJId1=[] + +def auau2for(id2): + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==xxinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + pass + +def auau3for(i1): + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==xxinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + + +def idid(deinput,data4,data5,data3): + global result,start_time,xxinput,FId1,AuId1,CJId1,Id3 + start_time = time.clock() + xxinput=deinput + result=[] + Id3=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + pool = ThreadPool(4) + pool.map(ididfor,data3["entities"]) + pool.close() + pool.join() + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result,start_time,ReId2,xxinput,AuId2,FId2,CJId2,Id1,AfId1 + Id1=[] + AfId1=[] + start_time = time.clock() + xxinput=deinput + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(idauidfor,data1["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result,start_time,Id1,AfId1,xxinput,FId2,AuId2,CJId2 + result=[] + Id1=[] + AfId1=[] + xxinput = deinput + start_time = time.clock() + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(auididfor,data1["entities"]) + pool.close() + pool.join() + + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result,start_time,AfId2,xxinput,Id2,Id1,AfId1 + result=[] + AfId2=[] + Id2=[] + Id1=[] + AfId1=[] + xxinput = deinput + start_time = time.clock() + print "XXXXXXXXXXauidauidXXXXXXXXXX" + + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + + pool = ThreadPool(4) + pool.map(auau2for,data2["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + pool = ThreadPool(4) + pool.map(auau3for,data1["entities"]) + pool.close() + pool.join() + + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1 - 副本.py b/test1 - 副本.py new file mode 100755 index 0000000..37b5b4b --- /dev/null +++ b/test1 - 副本.py @@ -0,0 +1,707 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json +import time +from multiprocessing.dummy import Pool as ThreadPool + + + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '1000000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '1000000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +def ididfor(i): + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([xxinput[0],tmp["FId"],i["Id"],xxinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([xxinput[0],tmp["AuId"],i["Id"],xxinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + pass + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + + +def idid(deinput,data4,data5,data3): + global result,start_time,xxinput,FId1,AuId1,CJId1,Id3 + start_time = time.clock() + xxinput=deinput + result=[] + Id3=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + pool = ThreadPool(4) + pool.map(ididfor,data3["entities"]) + pool.close() + pool.join() + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result,start_time + start_time = time.clock() + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result,start_time + result=[] + start_time = time.clock() + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result,start_time + result=[] + start_time = time.clock() + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1 - 副本.pyc b/test1 - 副本.pyc new file mode 100755 index 0000000000000000000000000000000000000000..adc765bdb83dbee03307f450d9f010ad02aa7aa8 GIT binary patch literal 16599 zcmd^GTWlQHc|J4C+wy*=D9bi2+s(?6DDfg$vgC^_MwDcSk%y|6X1t+?oT0STa+k9+ zw3jK>29<%rK+v})H4rq2+qbmtLs7I3MFSLl=u2%Bh=Il}P`HR2q;(A#2HF}Z(0<>4 zW_D+mE0a{6wob_1GiT=9&z%4J{{KH`Qy+J=zw_(U*%cN3rEq-;U;jlzDF+`z6_i>x z)S{u*O|@t$!!^`eO5IkxIe);rW6OSKvk^7Z1D3LMc3`yhx zVQx;{HqB_)X3n1!{~)f% z?G@W`*YhjKU!E90aol~`E^K00Pd@BtI*=^m+$u;2bm_4qQvTHkfk_x5p(VCBPT!w{`?f4RN z?7*JLaD7RIj+-xTYz9&R-phnM+_1~`x<4TgSI_}jpNY0u3*Um0z#l{G_ zE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lhx7Gq+3R1G6-hMZ@@a}0z%vWV@MI6RbD03-R|LPVun;1GgE(ttAJ zc1T1JgT{RgXrZ1aNG#Fun>)~i*eLXg(>Cb=S@ao0HOhcnNKW6i;wrWZJxF(;41#V- zRbH(vKkVa!LvTJ97!N#v(ZTb%gh!x-xUD0-9VkY$z$rBRE)$Xt?VS1{>XM&bhEFwG zysEsX`N7e)3}hOfU06KdB?;gjp9OqH7Fz3N0j?_?!9$4tfM-~p_s2SKl`SAW5nDid zG+Uqqpdu>q6O{#p%wFP1qpTQdyNne1I8v|zMoLzwA1MHbBRxvryo^-iV$mQjq9OfM zkF;obNBO}>`=PJuk-kO(z&$<-_+~55YIK!Po5@Wj4->s1kdN8{Dd+$onK4Xy zyBSs0SI`Fw-_TP+oT1J#2mg6oZzawoHCOFL7w-tQPz@ziJ2kQ(qQslr5K06^1W#&E z@*>L$l=Lz-${^{y;1Rt^YmEuwyb#1#8oaA}YS$8UKi?@0AZHwCmtBXmTs+xgx+|jvcJrSmI8>Dxb?_b~BNd#6DKAqnr;#K8~4 zam+fuQ7)~xzMn5%AIDzB`j$ln-ugA>p??TJ2=>M0kE7Uy{EA)u?eFzMY1u{^;R|W{ zb>GjjhZ$7&F!YwjvwS9|2CWQB=tEw-__|n!MGuliP2VDFTYLxBHUep(yjiThM2Y!h zNZZXTFEe~jJNKVxMgjjcf?>Qx{;u~S345Dc%ptSIO!v!wAHv7ehtv0^?@u2}X9hCq OUrjHkznVVNY5X@Kt^Sq( literal 0 HcmV?d00001 diff --git a/test1.py b/test1.py new file mode 100755 index 0000000..3ad74a4 --- /dev/null +++ b/test1.py @@ -0,0 +1,756 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent,os,sys +import web +import httplib, urllib, base64 +import json +import time +#from multiprocessing.dummy import Pool as ThreadPool +#from multiprocessing import Pool +#import multiprocessing, logging +#logger = multiprocessing.log_to_stderr() +#logger.setLevel(multiprocessing.SUBDEBUG) +#from gevent.pool import Pool +from multiprocessing import Process, Lock +lock = Lock() + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '1000000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '1000000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + print ">200" + return + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4 = data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '1000000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + now_time = time.clock() + exe_time = (float)(now_time - start_time) + if exe_time > 200: + return + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '1000000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +def ididfor(lock,i): + #lock.acquire() + with lock: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + #lock.release() +# id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + with lock: + result.append([xxinput[0],tmp["FId"],i["Id"],xxinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass +# id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + with lock: + result.append([xxinput[0],tmp["AuId"],i["Id"],xxinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass +# id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + with lock: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + with lock: + result.append([xxinput[0],CJId3,i["Id"],xxinput[1]]) + except(KeyError): + pass + +def idauidfor(i1): + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([xxinput[0],i1["Id"],xxinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([xxinput[0],x["AuId"],i1["Id"],xxinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([xxinput[0],x["FId"],i1["Id"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == xxinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],CJId2,i1["Id"],xxinput[1]]) + except: + CJId1=[] + +def auididfor(i1): + Id1.append(i1["Id"]) + if i1["Id"]==xxinput[1]: + result.append([xxinput[0],xxinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([xxinput[0],i1["Id"],tmp["FId"],xxinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([xxinput[0],i1["Id"],tmp["AuId"],xxinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==xxinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([xxinput[0],i1["Id"],CJId1,xxinput[1]]) + except: + CJId1=[] + +def auau2for(id2): + Id2.append(id2["Id"]) + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==xxinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + pass + +def auau3for(i1): + Id1.append(i1["Id"]) + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==xxinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + + +def idid(deinput,data4,data5,data3): + global result,start_time,xxinput,FId1,AuId1,CJId1,Id3 + start_time = time.clock() + xxinput=deinput + + result=[] + Id3=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + print "before data1" + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + print "before data2" + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + print "threads" + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + #p = Pool() + #for i in data3["entities"]: + # p.map(ididfor,i) + #p.map(ididfor,data3["entities"]) + #p.close() + #p.join() + threads = [] + for i in data3["entities"]: + p=Process(target=ididfor,args=(lock,i)) + p.daemon = True + threads.append(p) + for i in range(len(threads)): + threads[i].start() + for j in range(len(threads)): + threads[j].join() + + '''for data in data3["entities"]: + Process(target=ididfor,args=(data,)).start() + print "threads done"''' + print Id3 + '''for i in data3["entities"]: + p=Process(target=ididfor,args=(i,)) + p.start()''' + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + print "before gevent" + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result,start_time,ReId2,xxinput,AuId2,FId2,CJId2,Id1,AfId1 + Id1=[] + AfId1=[] + start_time = time.clock() + xxinput=deinput + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(idauidfor,data1["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result,start_time,Id1,AfId1,xxinput,FId2,AuId2,CJId2 + result=[] + Id1=[] + AfId1=[] + xxinput = deinput + start_time = time.clock() + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + pool = ThreadPool(4) + pool.map(auididfor,data1["entities"]) + pool.close() + pool.join() + + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result,start_time,AfId2,xxinput,Id2,Id1,AfId1 + result=[] + AfId2=[] + Id2=[] + Id1=[] + AfId1=[] + xxinput = deinput + start_time = time.clock() + print "XXXXXXXXXXauidauidXXXXXXXXXX" + + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + + pool = ThreadPool(4) + pool.map(auau2for,data2["entities"]) + pool.close() + pool.join() + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + pool = ThreadPool(4) + pool.map(auau3for,data1["entities"]) + pool.close() + pool.join() + + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1.pyc b/test1.pyc new file mode 100755 index 0000000000000000000000000000000000000000..23dfa9489dc8f25ef391d3239c437a86cbad944a GIT binary patch literal 17826 zcmd^HTWlQHc|K>CTylA*NL?t&Hf34XN|q?zB>5uSltk<5((*{g(hO*NxHF=bTJCL@ z_R=AdAWG4fz=e^t>643~DcYb9tqZh$Zi5!-OMwD)(I9|d+%!g8Bt?Th_^JKA|IEzJ zE?2zRNLwc)_w1QD|GDg$|NC#}U&epl-SM4)^XZK8f8uzb!pr*ut(1d5t#V4OXf>zR zN=(hgly@)9e2eeMb6?31=*%GocKCzW$R zD#w*GB$bqMPblZ0x*t>J-_!1ZT0SZJpO^i=oq7ZhEc@U1NySjBBv7mr^7q}fN-G~_ z&UK43rl}3rx5|Z#>v@$H)L$-S?t5LRoLMZ~otT(-F*WkkiApoC6kU#T%Y@8{Y7MlX%1P?8I9a_ww8W ztu|t+5+f^NOL-Yr>v6S=u6UY#YCWd*;rVIaYvrfiXi@7eYB?eGR-tW^UBGgelWHAA zTG_%hw^RLCF_xwv}W8Ge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{+pNLS~L9134a{43rQkkzs`& zZcL{_U6fFDisE{D{%KLdkb;N-Qrkg{QtpgsFf%iTefekzd>L69(fCV4rbFCA5*S|r zXvilOK~bX_*LyJH$7{2?dR?FDz$~GJk}b z&xRH*yPaY#)C>&mdO=0|F)FHPK29Ud zKRmuGA!S4llg6^Nk5ZCVC2plSljm{IyDV3w+e-v zSgq-6 z@)d1O!1W5?s%5(E)AP%MJKLP_ye>ZU1;HA2238g^U(|pMJ#B!U0ZRZ8jg$+x0l5$f zSeDM{K=%9wWecwHH;Y%g^tetFqV1}BRH9y3-1Pi@g&b4nn__slu{i4&Y=6hl!j^e=8@vo|r_PZR z3_l!Y)Sf^9MbzFH8A-@+>VmMgbel8`p%h#eDG}NN- zx{v~m&=kIeVzel>%E!z#U zFhS?75mDoQ9C<{!zrf1|2+Z@IK!AJ`fj~3H7j~!K*&(~Hf%LD*?o_@;S4CL9)o1BI z2ep`-;1luSJS*MUY%JV~77*U@2Evw9!U#w3!Dx%)Uoigi$#Yq!U-=4ja-eL|n-O z179j*jfjAg=PXZ`Hjp?JVkcOXHx{3Q_3J2P*79n;_VlE-RS-(H{(=c%y&!JYB@DC= zCc_hmfbrGUwofPHiP+v)B9`1Ezx^nmPd=V}H2GNaaPq0-@#M*5SF(E`m0ZI8^U0Ae F{XYi)Z}tEH literal 0 HcmV?d00001 diff --git a/test1_idid.py b/test1_idid.py new file mode 100755 index 0000000..bd7b8ae --- /dev/null +++ b/test1_idid.py @@ -0,0 +1,713 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + + + + + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + + + #id -> id -> XXXXXX -> id ************************************************************need gevent + '''for Reid in ReId1: + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]])''' + return result + +def idauid(deinput,data4,data2): + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for author2 in AuId2: + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + for rid in ReId2: + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + for Aid in Id1: + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + return result + +def auau(deinput,data1,data2): + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for aaid1 in Id1: + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1_idid_idauid.py b/test1_idid_idauid.py new file mode 100755 index 0000000..08685e2 --- /dev/null +++ b/test1_idid_idauid.py @@ -0,0 +1,663 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + for Aid in Id1: + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + return result + +def auau(deinput,data1,data2): + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for aaid1 in Id1: + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1_idid_idauid_auidid.py b/test1_idid_idauid_auidid.py new file mode 100755 index 0000000..f6cfe21 --- /dev/null +++ b/test1_idid_idauid_auidid.py @@ -0,0 +1,669 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for aaid1 in Id1: + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1_idid_idauid_auidid_auau.py b/test1_idid_idauid_auidid_auau.py new file mode 100755 index 0000000..5b3df77 --- /dev/null +++ b/test1_idid_idauid_auidid_auau.py @@ -0,0 +1,675 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#import gevent.monkey +#gevent.monkey.patch_socket() +from gevent import monkey, sleep +monkey.patch_all() +import gevent +import web +import httplib, urllib, base64 +import json + +urls=( + '/bof333?(.+)','get_user' +) +app = web.application(urls,globals()) + +result=[] + +def api1(deinput): + global data1 + exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data1=json.loads(data) + +def api2(deinput): + global data2 + exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'offset': '0', + 'model': 'latest', + 'count': '100000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + conn.close() + data2=json.loads(data) + +def api4(deinput): + global data4 + exp4 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp4, + 'model': 'latest', + 'offset': '0', + 'count': '100000', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + +def api5(deinput): + global data5 + exp5 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp5, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data5 = json.loads(data) + conn.close() + +def api3(deinput): + global data3 + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'model': 'latest', + 'attributes': 'Id,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + +def idid4api(Reid,deinput,FId2,AuId2,CJId2,Id3): + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + +def idauid3api(author2,deinput,AfId1): + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + +def idauid4api(rid,deinput,Id1): + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + +def auidid4api(Aid,deinput,Id3): + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + +def auau3api(aaid1,deinput,Id2): + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + +class get_user: + def GET(self,user): + input_data = web.input() + #input = [2157025439,2139398774] + input=[int(input_data.id1),int(input_data.id2)] + encodeinput = json.dumps(input) + deinput = json.loads(encodeinput) + print deinput + threads=[] + threads.append(gevent.spawn(api1,deinput)) + threads.append(gevent.spawn(api2,deinput)) + threads.append(gevent.spawn(api3,deinput)) + threads.append(gevent.spawn(api4,deinput)) + threads.append(gevent.spawn(api5,deinput)) + gevent.joinall(threads) + flag=0 + try: + print data1["entities"][0]["Id"] + except(KeyError,IndexError): + flag=10;#id1 is Id + try: + print data2["entities"][0]["Id"] + except(KeyError,IndexError): + flag+=1;#id2 is Id + if flag == 0: + result=auau(deinput,data1,data2) + elif flag == 1: + result=auidid(deinput,data1,data3,data5) + elif flag == 10: + result=idauid(deinput,data4,data2) + elif flag == 11: + result=idid(deinput,data4,data5,data3) + else: + print "FLAG : %d " % flag + deresult = json.dumps(result) + print deresult + print "Total Size: %d " % len(result) + return deresult + +def idid(deinput,data4,data5,data3): + global result + result=[] + print "XXXXXXXXXXididXXXXXXXXXXX" + data1 = data4 + data2 = data5 + #''''''''''''''''''data 1''''''''''''''''''''''''''' + try: + ReId1=data1["entities"][0]["RId"] + except (KeyError): + ReId1 = [] + try: + FId1 = data1["entities"][0]["F"] + except (KeyError): + FId1 = [] + try: + AuId1= data1["entities"][0]["AA"] + except (KeyError): + AuId1=[] + try: + CJId1= data1["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId1= data1["entities"][0]["C"]["CId"] + except: + CJId1=[] + + #''''''''''''''''''data 2''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #''''''''''''''''''data 3'''''''''id->XXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + try: + if i["Id"] not in Id3: + Id3.append(i["Id"]) + except(KeyError): + pass + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + threads=[] + for Reid in ReId1: + threads.append(gevent.spawn(idid4api,Reid,deinput,FId2,AuId2,CJId2,Id3)) + gevent.joinall(threads) + return result + +def idauid(deinput,data4,data2): + global result + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + + data1 = data2 + data2 = data4 + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for author2 in AuId2: + threads.append(gevent.spawn(idauid3api,author2,deinput,AfId1)) + gevent.joinall(threads) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for rid in ReId2: + threads.append(gevent.spawn(idauid4api,rid,deinput,Id1)) + gevent.joinall(threads) + return result + + +def auidid(deinput,data1,data3,data5): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + global result + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + data2 = data5 + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + threads=[] + for Aid in Id1: + threads.append(gevent.spawn(auidid4api,Aid,deinput,Id3)) + gevent.joinall(threads) + return result + +def auau(deinput,data1,data2): + global result + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + threads=[] + for aaid1 in Id1: + threads.append(gevent.spawn(auau3api,aaid1,deinput,Id2)) + gevent.joinall(threads) + + return result + +if __name__ == '__main__': + app.run() diff --git a/test1_idid_idauid_auidid_auau.pyc b/test1_idid_idauid_auidid_auau.pyc new file mode 100755 index 0000000000000000000000000000000000000000..88eff47f20dec30f49304bae090c6c1a8c4da98b GIT binary patch literal 15889 zcmd^GU2GiJb-s6Yxy$80#UF{1f8^MPSBXT4TuPQKE4D0Je|A-AKP5nc7AVldNq`2a(}y-dZ4{`38Z}xN4vaqZp$~m%00U0H z@7$T$ndQooEDNn#a`(=inS0N@bMLv|ch0%9ng8tVn*C*|yr{yz435v@>p!WLa`4e= zS*aDRX0=+e)U2hntJP9Q-B3#NzQy~qrY!PVHJg=s$akpOjwqi~v$-grSF`yj->GIh zl{2Dd3(C!^r7q`+dZ zWQLT}Etz5E^hjnzIlYn@RZgE|b}9$G#c4lJ(df5kcPVE;?u{vDP%^ufvqLg_lrtom z2bBAua)#A)OVvx-?NLh)$#~RcJT4b^VgReZ!C%orF32HSS*=}nH-Zih?Xv5xUGRI5 zJ-D!XrBo_CQyl-szMvBquDZeey6@H(G5U)2viP3D*MA!cCSy~Y7#rQvDo|=kt7=Yd zYUO0q5eJXbfdj@lj{}CafI}CD;Rr?m&wk{FR$G<|EKVSXfTtO?nNdrqiZLBfo0b~I zz-wOX;4^Jy)h6a8C;1L3o0n%rcb5uk6NR*@pb@1m7YEVD3;r&4d39xN)vpF_@#M+z zlk4Z4y(jiQ?(E%H#XS}9q1?t=J>XLwlJQx+a>aK8$u3s{*AHZy$jehTUN@$=`LpbLd7K~S$QtW)-0oL+fyadGn4 z;X}tNN2jJri-#9VmBa4gBMXPz($R&(l_UND3i;~`{$jnl7F1Vj2QYvBC@!uxuB_Ib zYuCpsZ>-nd1C_Pvcnw|8;MSSvU-Eb3c(Afqaom;a;=$J@#t$8IU#l#yLW-swmF>`O0QynJf4R&y8G2f1H&y>$){B|%^6 zuD`Zg!{BjL>u$v{gS5OFURv@|k9xPfT5){IIhCL?QKWi_K*z1t*4Be)S|;S;TBTlD z@h9ZsB03=InQDttI15S={~&S)S8BmQ|5~N)QnL?otS9EHPSrtDS;v8i94h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vxM322uF}rHtBGhj@EuN&jGa@7Oc1vr(elu5Xp5c|)?|X;sdaq>gnZdX0UCIct z464SXVt$Ff@8o-FpaSZ<{3uKG-TMbq7A`$Vh>jQ-1TOthnuKr#3^Ev#(63_>8ftZa z(hOpvf(Zsm(8jHOA43~-fXs^_!V`I(-qZoIc~=}DdFM(fLOdRVx$%O8ELxlza)M!p zE#`y~gfVD)+jS;F5aOsj&C?f{2wz-6?k=ff0V4Vkrt|+08I=*gr430Wy_JX(hV?^j zh@h1iNF~vG7&jpX@k8j_(EsQMJq+rRCP`$_FaDy0qc8pl5HRVF5N0!~@tvl^VdEIA zfwv-o>R38(EcjL=0TDJJ9A~^28`|c;E#iYX;#}LX${DF@$d4=V8#|Q5Rf7)=m}j`tQW%%r~z<@ zYJ8;1SSDxA@=2qjvPI4(ML9kxcmPjI9%y}1Kn$OBFL!X{NevP%Xd+?DlP+j)FF$zF z9Bfkaq+5i1oZ~ZtZ@KZJ!INnroZ}p^>A6z+Z7uAM$Qv~T5p)0`%p3+i+^+Y&r|~I! z-!yBvP}o!hh$sf zehPM3lC~+4C2gIWy_Rv560|VjLC6qGQ?_Fg(Gv-r$eSq5=*jQ0uz&|u-9%5);S#=O zHEF-hyAlx*jChHsEeIlzA>bj9AwY2%kY#6@W zx>Rbd5-eVu=WbG&*BK;}pQ_0Q(L%*{k4%}ZD_EWU>7_5bJ$Mavxw=@1e`R@fd3B+J zd&D8!GX&7w!+MNTpJ4KJCK3h{mx11bEuXXXX->id->id''''''''''''''''''maybe big enough > 10w + Id3 = [] + FId3 = [] + AuId3 = [] + CJId3 = [] + for i in data3["entities"]: + # id -> F.FId -> id -> id + try: + FId_data3 = i["F"] + for tmp in FId_data3: + for x in FId1: + if x["FId"]==tmp["FId"]: + result.append([deinput[0],tmp["FId"],i["Id"],deinput[1]]) + #FId3.append(tmp["FId"])# + except(KeyError): + pass + # id -> AA.AuId -> id -> id + try: + AuId_data3=i["AA"] + for tmp in AuId_data3: + for x in AuId1: + if x["AuId"]==tmp["AuId"]: + result.append([deinput[0],tmp["AuId"],i["Id"],deinput[1]]) + #AuId3.append(tmp["AuId"])#'''''''''''''''''''''need optimization + except(KeyError): + pass + # id -> C.CId/J.JId -> id -> id + try: + CJId3=i["J"]["JId"]#'''''''''''''''''''''need optimization + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + try: + CJId3=i["C"]["CId"] + if CJId3==CJId1: + result.append([deinput[0],CJId3,i["Id"],deinput[1]]) + except(KeyError): + pass + + #''''''''''''''''''operation''''''''''1 and 2 hop''''''''''''''''' + #id -> id + for Reid in ReId1: + if deinput[1] == Reid: + result.append([deinput[0],Reid]) + break + #id -> F.FId -> id + for x in FId2: + #print 'x: %d ' % x['FId'] + for y in FId1: + #print y['FId'] + if y['FId']==x['FId']: + result.append([deinput[0],x['FId'],deinput[1]]) + #id -> AA.AuId -> id + for x in AuId2: + for y in AuId1: + if y['AuId']==x['AuId']: + result.append([deinput[0],x['AuId'],deinput[1]]) + #id -> C.CId/J.JId -> id + if CJId1==CJId2: + result.append([deinput[0],CJId1,deinput[1]]) + + #''''''''''''''''''''4th API''''''''''''''''''''''''''''' + #id -> id -> XXXXXX -> id ************************************************************need gevent + for Reid in ReId1: + exp4 = 'Id = %d' % Reid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'model': 'latest', + 'attributes': 'RId,F.FId,AA.AuId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + try: + FId4 = data4["entities"][0]["F"] + except (KeyError): + FId4 = [] + try: + AuId4= data4["entities"][0]["AA"] + except (KeyError): + AuId4=[] + try: + CJId4= data4["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId4= data4["entities"][0]["C"]["CId"] + except: + CJId4=[] + + #id -> id -> id #id -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Reid,deinput[1]]) + for Id in Id3: + if rid == Id: + result.append([deinput[0],Reid,rid,deinput[1]]) + #id -> id -> F.FId -> id + for x in FId2: + for y in FId4: + if y['FId']==x['FId']: + result.append([deinput[0],Reid,x['FId'],deinput[1]]) + #id -> id -> AA.AuId -> id + for x in AuId2: + for y in AuId4: + if y['AuId']==x['AuId']: + result.append([deinput[0],Reid,x['AuId'],deinput[1]]) + #id -> id -> C.CId/J.JId -> id + if CJId4==CJId2: + result.append([deinput[0],Reid,CJId4,deinput[1]]) + return result + +def idauid(deinput,data2): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + result=[] + print "XXXXXXXXXXidauidXXXXXXXXXXX" + '''exp1 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '10000', + 'attributes': 'Id,AA.AuId,AA.AfId,F.FId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data1 = json.loads(data) + conn.close()''' + data1 = data2 + #'''''''''''''''''''''''''2nd API''''''''''''''''''''''''''''''''' + exp2 = 'Id = %d' % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp2, + 'model': 'latest', + 'count': '10000', + 'attributes': 'RId,AA.AuId,AA.AfId,F.FId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data2 = json.loads(data) + conn.close() + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + print ("Data 2") + print data2 + + try: + ReId2 = data2["entities"][0]["RId"] + except (KeyError): + ReId2 = [] + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2 = data2["entities"][0]["AA"] + except (KeyError): + AuId2 = [] + try: + CJId2 = data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2 = data2["entities"][0]["C"]["CId"] + except: + CJId2 =[] + + for tmp in AuId2: + if deinput[1] == tmp["AuId"]: + result.append([deinput[0],deinput[1]]) # Id -> AA.AuId (1-hop) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + print ("Data1") + print data1 + + AfId1=[] + Id1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + for tmp in ReId2: + if i1["Id"] == tmp:# Id -> Id -> AA.AuId (2-hop) + result.append([deinput[0],i1["Id"],deinput[1]]) + for tmp in i1["AA"]: + for x in AuId2: + if x["AuId"] == tmp["AuId"]: + # Id -> AA.AuId -> Id -> AA.AuId (3-hop) (new add~~) + result.append([deinput[0],x["AuId"],i1["Id"],deinput[1]]) + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"] == tmp["FId"]: + # Id -> F.FId -> Id -> AA.AuId (3-hop) + result.append([deinput[0],x["FId"],i1["Id"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in i1["AA"]: + if tmp["AuId"] == deinput[1]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + pass + try: + CJId1 = i1["J"]["JId"] # Id -> C.CId/J.JId -> Id -> AA.AuId (3-hop) + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],CJId2,i1["Id"],deinput[1]]) + except: + CJId1=[] + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for author2 in AuId2: + exp3 = "Composite(AA.AuId = %d )" % author2["AuId"] + params1 = urllib.urlencode({ + 'expr':exp3, + 'model': 'latest', + 'count': '10000', + 'attributes': 'AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + AfId3=[] + for i3 in data3["entities"]: + try: + for tmp in i3["AA"]: + if tmp["AuId"] == author2["AuId"]: + if tmp["AfId"] not in AfId3: + AfId3.append(tmp["AfId"]) + break + except (KeyError): + pass + for x in AfId3: + for y in AfId1: + if x == y : + result.append([deinput[0],author2["AuId"],x,deinput[1]]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + for rid in ReId2: + exp4 = 'Id = %d' % rid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '10000', + 'model': 'latest', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id -> id + for rid4 in ReId4: + for tmp in Id1: + if rid4 == tmp: + result.append([deinput[0],rid,rid4,deinput[1]]) + return result + + +def auidid(deinput,data1): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + result=[] + print "XXXXXXXXXXauididXXXXXXXXXXX" + '''exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr':exp1, + 'offset': '0', + 'model': 'latest', + 'count': '10000', + 'attributes': 'Id,RId,F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data1 = json.loads(data) + conn.close()''' + #print data + + #'''''''''''''''''''''''''2nd API''''''''''''''''''''''''''''''''' + exp2 = 'Id = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'count': '100000', + 'model': 'latest', + 'attributes': 'F.FId,AA.AuId,AA.AfId,C.CId,J.JId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data2 = json.loads(data) + conn.close() + #print data2 + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + exp3 = 'RId = %d' % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '10000', + 'attributes': 'Id', + 'model': 'latest', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + try: + FId2 = data2["entities"][0]["F"] + except (KeyError): + FId2 = [] + try: + AuId2= data2["entities"][0]["AA"] + except (KeyError): + AuId2=[] + try: + CJId2= data2["entities"][0]["J"]["JId"] + except (KeyError): + try: + CJId2= data2["entities"][0]["C"]["CId"] + except: + CJId2=[] + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + if i1["Id"]==deinput[1]: + result.append([deinput[0],deinput[1]]) # AA.AuId -> Id + try: + FId1 = i1["F"] + for tmp in FId1: + for x in FId2: + if x["FId"]==tmp["FId"]: + # AA.AuId -> Id -> F.FId -> Id + result.append([deinput[0],i1["Id"],tmp["FId"],deinput[1]]) + except (KeyError): + pass + try: + AuId1= i1["AA"] + for tmp in AuId1: + for x in AuId2: + if tmp["AuId"]==x["AuId"]: + # AA.AuId -> Id -> AA.AuId -> Id + result.append([deinput[0],i1["Id"],tmp["AuId"],deinput[1]]) + except (KeyError): + pass + try: + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except(KeyError): + pass + try: + CJId1= i1["J"]["JId"] # AA.AuId -> Id -> C.CId/J.JId -> Id + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except (KeyError): + try: + CJId1= i1["C"]["CId"] + if CJId1 == CJId2: + result.append([deinput[0],i1["Id"],CJId1,deinput[1]]) + except: + CJId1=[] + # AA.AuId -> AA.AfId -> AA.AuId -> Id + for x in AuId2: + for y in AfId1: + try: + if y==x["AfId"]: + result.append([deinput[0],y,x["AuId"],deinput[1]]) + except(KeyError): + continue + + + #'''''''''''''''''''''data 3'''''''''''''''''''''''''''''''' + Id3 = [] + for i3 in data3["entities"]: + Id3.append(i3["Id"]) + + #************************************************************need gevent + #''''''''''''''''''''4th API'''''''''''''''''''''''''''''''''''' + for Aid in Id1: + exp4 = 'Id = %d' % Aid + params1 = urllib.urlencode({ + 'expr':exp4, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data4 = json.loads(data) + conn.close() + #print data4 + try: + ReId4= data4["entities"][0]["RId"] + except (KeyError): + ReId4 = [] + # AA.AuId -> id -> id # AA.AuId -> id -> id -> id + for rid in ReId4: + if deinput[1] == rid: + result.append([deinput[0],Aid,deinput[1]]) + for tmp in Id3: + if rid == tmp: + result.append([deinput[0],Aid,rid,deinput[1]]) + return result + +def auau(deinput,data1,data2): + #'''''''''''''''''''''''''1st API''''''''''''''''''''''''''''''''' + result=[] + print "XXXXXXXXXXauidauidXXXXXXXXXX" + '''exp1 = "Composite(AA.AuId = %d )" % deinput[0] + params1 = urllib.urlencode({ + 'expr': exp1, + 'model': 'latest', + 'offset': '0', + 'count': '10000', + 'attributes': 'Id,AA.AfId,AA.AuId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data1 = json.loads(data) + conn.close()''' + #'''''''''''''''''''''''''2nd API''''''''''''''''''''''''''''''''' + '''exp2 = "Composite(AA.AuId = %d )" % deinput[1] + params1 = urllib.urlencode({ + 'expr':exp2, + 'count': '1000', + 'model': 'latest', + 'attributes': 'Id,AA.AuId,AA.AfId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data2 = json.loads(data) + conn.close()''' + + #'''''''''''''''''''''data 2'''''''''''''''''''''''''''''''' + AfId2=[] + for id2 in data2["entities"]: + try: + AuId2= id2["AA"] + for tmp in AuId2: + if tmp["AuId"]==deinput[1]: + if tmp["AfId"] not in AfId2: + AfId2.append(tmp["AfId"]) + break + except (KeyError): + continue + Id2=[] + for id2 in data2["entities"]: + Id2.append(id2["Id"]) + + #'''''''''''''''''''''data 1'''''''''''''''''''''''''''''''' + #print data1 + Id1=[] + AfId1=[] + for i1 in data1["entities"]: + Id1.append(i1["Id"]) + print Id1 + for i1 in data1["entities"]: + try: + AuId1= i1["AA"] + for tmp in AuId1: + if tmp["AuId"]==deinput[0]: + if tmp["AfId"] not in AfId1: + AfId1.append(tmp["AfId"]) + break + except (KeyError): + continue + + + # AA.AuId -> AA.AfId -> AA.AuId + for x in AfId1: + for y in AfId2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + # AA.AuId -> Id -> AA.AuId + for x in Id1: + for y in Id2: + if x==y: + result.append([deinput[0],x,deinput[1]]) + + #'''''''''''''''''''''''''3rd API''''''''''''''''''''''''''''''''' + for aaid1 in Id1: + exp3 = 'Id = %d' % aaid1 + params1 = urllib.urlencode({ + 'expr':exp3, + 'count': '100000', + 'attributes': 'RId', + 'subscription-key': 'f7cc29509a8443c5b3a5e56b0e38b5a6', + }) + conn = httplib.HTTPSConnection('oxfordhk.azure-api.net') + conn.request("GET", "/academic/v1.0/evaluate?%s" % params1) + response = conn.getresponse() + data = response.read() + data3 = json.loads(data) + conn.close() + try: + ReId3=data3["entities"][0]["RId"] + except (KeyError): + ReId3 = [] + # AA.AuId -> Id -> Id -> AA.AuId + for x in ReId3: + for y in Id2: + if x==y: + result.append([deinput[0],aaid1,x,deinput[1]]) + return result + +if __name__ == '__main__': + app.run() diff --git a/test1副本.pyc b/test1副本.pyc new file mode 100755 index 0000000000000000000000000000000000000000..e9020cd55fb87f3d13c6fd7f7a644e4c41abcd19 GIT binary patch literal 12695 zcmc&)U2GiJb-pwE!zIQ4Us0lDQnp$uu}D#*XvtP&QKUslPE}d)a4{ZYoEz$=YLHm8@ z&dkm%sUKGnO77gbbMLw5o_p?{d%kn-B>tZ2Szht<U>FP;RPQW{^*)TZtf_RJW4KZd12XDzDU5TIG>xQFoQPizXSh35Ko82K@nLC)Kx5 zuGH6WwJAHrhg&F3OQv1fEt2U_c1ALtD&M8-R(0D{mG7&3Ms0Pou~8IBm&V&6b>V;T zcim-na;>y6Jw5&E_{5h_co`II=DpP&H(yytUj7WEmvFf~NFc2q9i=dpwKUG^brT7z z)41kwxgVj#!^jNwT{o3ys+y^`66&rI3gRKtVyw1T8tt*U@FX=-WKhBi~U;i(0;3>7d7{X%`SHgwdXX3<%_MR{#%3(D(c z-}Q{Dfe)&oux?drQG?LF!Lkk!yH(X%)fQ+mgtk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