-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_handlers.py
240 lines (160 loc) · 9.53 KB
/
socket_handlers.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
from fastapi import FastAPI
from fastapi_socketio import SocketManager
from fastapi.middleware.cors import CORSMiddleware
import numpy as np
import pandas as pd
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
sio = SocketManager(app=app)
data = {
'Çalışan': ['Ahmet Yılmaz','Can Ertürk','Hasan Korkmaz','Cenk Saymaz','Ali Turan','Rıza Ertürk','Mustafa Can', "Gökhan Türkaslan", 'Aylin Yıldırım', 'Esra Korkmaz', 'Zeynep Aydın', 'Ali Kaya', 'Fatma Demir', 'Mehmet Aksoy', 'Ayşe Yılmaz'],
'Departman': ['İnsan Kaynakları','Bilgi İşlem','Muhasebe','İnsan Kaynakları','Bilgi İşlem','Muhasebe','Bilgi İşlem', "Bilgi İşlem", "İnsan Kaynakları", 'Reklamcılık', 'Halkla İlişkiler', 'İnsan Kaynakları', 'Bilgi İşlem', 'İnsan Kaynakları', 'Grafik Tasarım'],
'Yaş': [30,25,45,50,23,34,42, 20, 46, 25, 45, 50, 63, 19, 56],
'Semt': ['Kadıköy','Tuzla','Maltepe','Tuzla','Kadıköy','Tuzla','Maltepe', "Maltepe", "Kadıköy", 'Sultanbeyli' , 'Sancaktepe', 'Çekmeköy', 'Kartal', 'Kadıköy', 'Pendik'],
'Maaş': [5000,3000,4000,3500,2750,6500,4500, 4000, 3000, 2800, 4600, 8700, 3700, 2750, 4000]
}
dataSeries = pd.DataFrame(data) # Pandas İşlemleri yapabilmek için veriyi Pandas Serisi'ne çevirdim.
@app.get("/")
async def main():
return {"message": "Sunucu Açık"}
# Data Set'i görebileceğim, yerine göre kullanabileceğim bi route açtım
@app.get("/dataset")
async def main():
return data
# Table Data giden veri
@app.sio.on('tableLoad')
async def tableLoad(sid, *args, **kwargs):
await sio.emit('tableDatas', data)
# Index Echart
@app.sio.on('loadIndexChart')
async def tableLoad(sid, *args, **kwargs):
agesAndSalary = dataSeries[['Çalışan','Yaş', 'Maaş']]
await sio.emit('echartIndexData', agesAndSalary.to_json())
# Index Avg Datas
@app.sio.on('avgDatasLoad')
async def tableLoad(sid, *args, **kwargs):
avgSalary = dataSeries['Maaş'].mean()
avgAge = dataSeries['Yaş'].mean()
allData = {"Ortalama Maaş": round(avgSalary, 2), "Ortalama Yaş": round(avgAge, 2)}
await sio.emit('avgDatas', allData)
@app.sio.on('loadDepartmentPageData')
async def loadDepartmentPageData(sid, *args, **kwargs):
numberOfEmployees = dataSeries.groupby('Departman')['Çalışan'].count() #Departmana göre çalışan sayısı
await sio.emit('numberofEmployees', numberOfEmployees.to_json())
@app.sio.on('accDetail')
async def accDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Departman').get_group('Muhasebe')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #Muhasebe departmanına göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('accDetailData', employeeDeatilsOfAcc.to_json())
@app.sio.on('hrDetail')
async def hrDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Departman').get_group('İnsan Kaynakları')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #İnsan Kaynakları departmanına göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('hrDetailData', employeeDeatilsOfAcc.to_json())
@app.sio.on('itDetail')
async def itDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Departman').get_group('Bilgi İşlem')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #Bilgi İşlem departmanına göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('itDetailData', employeeDeatilsOfAcc.to_json())
@app.sio.on('loadDepartmentChart')
async def loadDepartmentChart(sid, *args, **kwargs):
numberOfEmployees = dataSeries.groupby('Departman')['Çalışan'].count() #Departmana göre çalışan sayısı
avgAgeByDepartment = dataSeries.groupby('Departman')['Yaş'].mean() # departmana göre yaş ortalaması
avgSalaryByDepartment = dataSeries.groupby('Departman')['Maaş'].mean() # departmana göre yaş ortalaması
totalSalaryExpandByDepertment = dataSeries.groupby('Departman')['Maaş'].sum() # Departmandaki toplam maaş harcaması
employeesByDepartment = dataSeries.groupby('Departman')['Çalışan'].count() # Departmana göre çalışan bilgisi
allDatas = pd.Series(data=[numberOfEmployees, avgAgeByDepartment, avgSalaryByDepartment, totalSalaryExpandByDepertment, employeesByDepartment], index=['Çalışan Sayısı', 'Yaş Ortalaması', 'Maaş Ortalaması', 'Toplam Maaş Harcaması', 'Departman Bazında Çalışanlar'])
await sio.emit('echartDepartmentData', allDatas.to_json())
@app.sio.on('loadPageForEmployeCount')
async def loadPageForEmployeCount(sid, *args, **kwargs):
numberOfEmployees = dataSeries.groupby('Semt')['Çalışan'].count() #Semte göre çalışan sayısı
await sio.emit('numberofEmployeesByCities', numberOfEmployees.to_json())
@app.sio.on('kadikoyDetail')
async def kadıkoyDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Semt').get_group('Kadıköy')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #Kadıköy semtine göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('kadikoyData', employeeDeatilsOfAcc.to_json())
@app.sio.on('maltepeDetail')
async def maltepeDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Semt').get_group('Maltepe')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #Kadıköy semtine göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('maltepeData', employeeDeatilsOfAcc.to_json())
@app.sio.on('tuzlaDetail')
async def tuzlaDetail(sid, *args, **kwargs):
employeeDeatilsOfAcc = dataSeries.groupby('Semt').get_group('Tuzla')[['Çalışan', 'Maaş', 'Yaş', 'Semt']] #Kadıköy semtine göre calisan, maas, yas ve semt bilgileri
clickCounter = args[0]
if(clickCounter <= 1):
await sio.emit('tuzlaData', employeeDeatilsOfAcc.to_json())
@app.sio.on('loadCitiesChart')
async def loadCitiesChart(sid, *args, **kwargs):
numberOfEmployees = dataSeries.groupby('Semt')['Çalışan'].count() #Semte göre çalışan sayısı
avgAgeByCities = dataSeries.groupby('Semt')['Yaş'].mean() # Semte göre yaş ortalaması
avgSalaryByCities = dataSeries.groupby('Semt')['Maaş'].mean() # Semte göre yaş ortalaması
allAgesByCities = dataSeries.groupby('Semt')['Yaş'].apply(list) # Semtlere göre tüm yaşlar
totalSalaryExpandByCities = dataSeries.groupby('Semt')['Maaş'].sum() # Semtlerdeki toplam maaş harcaması
allDatas = pd.Series(data=[numberOfEmployees, avgAgeByCities, avgSalaryByCities, totalSalaryExpandByCities, allAgesByCities ], index=['Çalışan Sayısı', 'Yaş Ortalaması', 'Maaş Ortalaması', 'Toplam Maaş Harcaması', 'Semtlere Göre Tüm Yaşlar'])
await sio.emit('citiesChartData', allDatas.to_json())
@app.sio.on('tableLoadOlderEmployee')
async def tableLoadOlderEmployee(sid, *args, **kwargs):
olderEmployee = dataSeries[dataSeries['Yaş'] == dataSeries['Yaş'].max()]
await sio.emit('olderEmployeeData', olderEmployee.to_json())
@app.sio.on('tableLoadYoungestEmployee')
async def tableLoadYoungestEmployee(sid, *args, **kwargs):
youngestEmployee = dataSeries[dataSeries['Yaş'] == dataSeries['Yaş'].min()]
await sio.emit('youngestEmployeeData', youngestEmployee.to_json())
@app.sio.on('tableLoadHighestEmployee')
async def tableLoadHighestEmployee(sid, *args, **kwargs):
highestEmployee = dataSeries[dataSeries['Maaş'] == dataSeries['Maaş'].max()]
await sio.emit('highestEmployeeData', highestEmployee.to_json())
@app.sio.on('tableLoadLowestEmployee')
async def tableLoadLowestEmployee(sid, *args, **kwargs):
lowestEmployee = dataSeries[dataSeries['Maaş'] == dataSeries['Maaş'].min()]
await sio.emit('lowestEmployeeData', lowestEmployee.to_json())
@app.sio.on('tableLoadHighestDepart')
async def tableLoadHighestDepart(sid, *args, **kwargs):
lowestEmployee = dataSeries.groupby('Departman')['Maaş'].mean().idxmax()
await sio.emit('highestDepartData', lowestEmployee)
@app.sio.on('tableLoadPopularCity')
async def tableLoadPopularCity(sid, *args, **kwargs):
popularCity = dataSeries['Semt'].value_counts().idxmax()
await sio.emit('popularCityData', popularCity)
@app.sio.on('loadSalaryChart')
async def tableLoadPopularCity(sid, *args, **kwargs):
salaryDatas = dataSeries[['Maaş', 'Çalışan']]
await sio.emit('echartSalaryData', salaryDatas.to_json())
@app.sio.on('calculate1')
async def calculate1(sid, *args, **kwargs):
personData = args[0][0]
budgetData = args[0][1]
salaryThatCanBeGiven = int(budgetData) / int(personData)
await sio.emit('calculateData1', [round(salaryThatCanBeGiven, 2)])
@app.sio.on('calculate2')
async def calculate1(sid, *args, **kwargs):
budgetData = args[0][0]
minSalary = args[0][1]
numberOfEmployee = int(budgetData) / int(minSalary)
await sio.emit('calculateData2', int(numberOfEmployee))
@app.sio.on('totalSalaryOfEmployee')
async def totalSalaryOfEmployee(sid, *args, **kwargs):
allSalaries = dataSeries['Maaş'].values
totalSalary = np.sum(allSalaries)
await sio.emit('totalSalaryOfEmployeeData', int(totalSalary))
if __name__ == '__main__':
import logging
import sys
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
import uvicorn
uvicorn.run("socket_handlers:app", host='127.0.0.1', port=8081, reload=True)