-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonepe.py
295 lines (205 loc) · 9.26 KB
/
Phonepe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import os
import json
import pandas as pd
import numpy as np
import pymysql
import mysql.connector
import streamlit as st
import plotly.express as px
from streamlit_option_menu import option_menu
import PIL
from PIL import Image
import geopandas as gpd
import matplotlib.pyplot as plt
import plotly as plot
from geopandas import plotting
import requests
import json
from sqlalchemy.engine import URL
from sqlalchemy import create_engine
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="DatascienceProject098",
)
print(mydb)
mycursor = mydb.cursor(buffered=True)
alchemydb= create_engine('mysql+mysqlconnector://root:DatascienceProject098@localhost/Phonepe')
#Dashboard Configuratin
st.set_page_config(layout='wide', page_title='PhonePe Data Analysis')
#Transcation_Aggerate
Trans_Agg_Path="C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/aggregated/transaction/country/india/state/"
Trans_Agg_list= os.listdir(Trans_Agg_Path)
Table1={"States":[], "Years":[], "Quarter":[], "Transcation_type": [], "Transcation_count": [], "Transcation_amount":[]}
for state in Trans_Agg_list:
states_details = Trans_Agg_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
pri=json.load(data)
for i in pri["data"]["transactionData"]:
name=i["name"]
count=i["paymentInstruments"][0]["count"]
amount=i["paymentInstruments"][0]["amount"]
Table1["Transcation_type"].append(name)
Table1["Transcation_count"].append(count)
Table1["Transcation_amount"].append(amount)
Table1["States"].append(state)
Table1["Years"].append(year)
Table1["Quarter"].append(int(file.strip(".json")))
Table1
Agg_Transcation=pd.DataFrame(Table1)
User_Aggre_Path="C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/aggregated/user/country/india/state/"
User_Aggre_List=os.listdir(User_Aggre_Path)
Table2={"States":[],"Year":[],"Quarter":[],"Brand":[],"Transcation_count":[],"Percentage":[]}
for state in User_Aggre_List:
states_details = User_Aggre_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
useaggpth=json.load(data)
print(useaggpth)
try:
for i in useaggpth["data"]["usersByDevice"]:
brand=i["brand"]
count=i["count"]
percentage=i["percentage"]
Table2["Brand"].append(brand)
Table2["Transcation_count"].append(count)
Table2["Percentage"].append(percentage)
Table2["States"].append(state)
Table2["Year"].append(year)
Table2["Quarter"].append(int(file.strip(".json")))
except:
pass
User_aggerator_Transcation=pd.DataFrame(Table2)
#Map Transcation Path
Map_Transcation_Path = "C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/map/transaction/hover/country/india/state/"
Map_Transcation_List= os.listdir(Map_Transcation_Path)
Table3={"States":[],"Year":[],"Quarter":[],"District":[],"Transcation_count":[],"Transcation_amount":[]}
for state in Map_Transcation_List:
states_details = Map_Transcation_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
maptrnspth=json.load(data)
for i in maptrnspth["data"]["hoverDataList"]:
name=i["name"]
count=i['metric'][0]['count']
amount=i['metric'][0]['amount']
Table3["District"].append(name)
Table3["Transcation_count"].append(count)
Table3["Transcation_amount"].append(amount)
Table3["States"].append(state)
Table3["Year"].append(year)
Table3["Quarter"].append(int(file.strip(".json")))
Map_Transcation_Aggera=pd.DataFrame(Table3)
print(Map_Transcation_Aggera)
#Map User Agger
Map_User_Agger_Path="C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/map/user/hover/country/india/state/"
Map_User_Agger_List=os.listdir(Map_User_Agger_Path)
Table4={"States":[],"Year":[],"Quarter":[],"District":[],"Registered_Users":[],"App_Opens":[]}
for state in Map_User_Agger_List:
states_details = Map_User_Agger_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
Mapuseragg=json.load(data)
for i in Mapuseragg["data"]["hoverData"].items():
district=i[0]
registeredUsers=i[1]["registeredUsers"]
appOpens=i[1]["appOpens"]
Table4["District"].append(district)
Table4["Registered_Users"].append(registeredUsers)
Table4["App_Opens"].append(appOpens)
Table4["States"].append(state)
Table4["Year"].append(year)
Table4["Quarter"].append(int(file.strip(".json")))
Map_User_Agger_Table=pd.DataFrame(Table4)
#Top Transcation Path
Top_Transcation_Path = "C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/top/transaction/country/india/state/"
Top_Transcation_List= os.listdir(Top_Transcation_Path)
Table5={"States":[],"Year":[],"Quarter":[],"District":[],"Transcation_count":[],"Transcation_amount":[]}
for state in Top_Transcation_List:
states_details = Top_Transcation_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
toptrnspth=json.load(data)
for i in toptrnspth["data"]["districts"]:
name=i["entityName"]
count=i["metric"]["count"]
amount=i["metric"]["amount"]
Table5["District"].append(name)
Table5["Transcation_count"].append(count)
Table5["Transcation_amount"].append(amount)
Table5["States"].append(state)
Table5["Year"].append(year)
Table5["Quarter"].append(int(file.strip(".json")))
Top_Transcation_List=pd.DataFrame(Table5)
#Top User Transcation
Top_User_Path = "C:/Users/subash/OneDrive/Guvi/Project/PhonePe/pulse/data/top/user/country/india/state/"
Top_User_Path_List=os.listdir(Top_User_Path)
Table61={"States":[],"Year":[],"Quarter":[],"Disname":[],"Dreguser":[]}
Table62={"Pincode_Name":[],"Pincode_Reguser":[]}
for state in Top_User_Path_List:
states_details = Top_User_Path+state+"/"
Agg_Year_list = os.listdir(states_details) #convert the string into location path
#print(Agg_Year_list)
for year in Agg_Year_list:
cur_year = states_details+year+"/"
Agg_File_List = os.listdir(cur_year)
#print(Agg_File_List)
for file in Agg_File_List:
cur_file = cur_year + file
data = open(cur_file,"r")
topuserpth=json.load(data)
#topuserdict=dict(topuserpth["data"])
for i in topuserpth["data"]["districts"]:
dname=i["name"]
#print(dname)
dreguser=i["registeredUsers"]
#print(dreguser)
Table61["Disname"].append(dname)
Table61["Dreguser"].append(dreguser)
Table61["States"].append(state)
Table61["Year"].append(year)
Table61["Quarter"].append(int(file.strip(".json")))
for i in topuserpth["data"]["pincodes"]:
pname=i["name"]
preguser=i["registeredUsers"]
Table62["Pincode_Name"].append(pname)
Table62["Pincode_Reguser"].append(preguser)
Top_User_Table1=pd.DataFrame(Table61)
Top_User_Table2=pd.DataFrame(Table62)
Top_User_Table=Top_User_Table1.join(Top_User_Table2)