Skip to content

Commit e1b1f41

Browse files
last commit
1 parent 19f3ef9 commit e1b1f41

File tree

244 files changed

+31458
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+31458
-0
lines changed

.circleci/config.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use the latest 2.1 version of CircleCI pipeline process engine.
2+
# See: https://circleci.com/docs/2.0/configuration-reference
3+
version: 2.1
4+
5+
# Define a job to be invoked later in a workflow.
6+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
7+
jobs:
8+
say-hello:
9+
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
10+
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
11+
docker:
12+
- image: cimg/base:stable
13+
# Add steps to the job
14+
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
15+
steps:
16+
- checkout
17+
- run:
18+
name: "Say hello"
19+
command: "echo Hello, World!"
20+
21+
# Invoke jobs via workflows
22+
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
23+
workflows:
24+
say-hello-workflow:
25+
jobs:
26+
- say-hello

apps/accounts/__init__.py

Whitespace-only changes.
159 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.
389 Bytes
Binary file not shown.
309 Bytes
Binary file not shown.
Binary file not shown.
319 Bytes
Binary file not shown.

apps/accounts/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

apps/accounts/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountConfig(AppConfig):
5+
# default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'apps.accounts'

apps/accounts/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib.auth.models import User
2+
3+
User._meta.get_field('email')._unique = True
4+
User._meta.get_field('email').blank = False
5+
User._meta.get_field('email').null = False

apps/accounts/serializers.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
from django.contrib.auth import authenticate, get_user_model
3+
from djoser.conf import settings
4+
from djoser.serializers import TokenCreateSerializer
5+
6+
User = get_user_model()
7+
8+
class CustomTokenCreateSerializer(TokenCreateSerializer):
9+
10+
def validate(self, attrs):
11+
password = attrs.get("password")
12+
params = {settings.LOGIN_FIELD: attrs.get(settings.LOGIN_FIELD)}
13+
self.user = authenticate(
14+
request=self.context.get("request"), **params, password=password
15+
)
16+
if not self.user:
17+
self.user = User.objects.filter(**params).first()
18+
if self.user and not self.user.check_password(password):
19+
self.fail("invalid_credentials")
20+
if self.user: # and self.user.is_active:
21+
return attrs
22+
self.fail("invalid_credentials")

apps/accounts/tests.py

Whitespace-only changes.

apps/accounts/urls.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.conf.urls import url, include
2+
3+
accounts_urlpatterns = [
4+
url(r'^api/v1/', include('djoser.urls')),
5+
url(r'^api/v1/', include('djoser.urls.authtoken')),
6+
]

apps/accounts/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

apps/analytics/__init__.py

Whitespace-only changes.
160 Bytes
Binary file not shown.
201 Bytes
Binary file not shown.
450 Bytes
Binary file not shown.
691 Bytes
Binary file not shown.
Binary file not shown.
375 Bytes
Binary file not shown.
6.04 KB
Binary file not shown.

apps/analytics/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

apps/analytics/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AnalyticsConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'apps.analytics'
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 3.2.9 on 2021-11-14 03:29
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
('master', '0008_alter_master_options'),
13+
('testing', '0001_initial'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='Analytics',
19+
fields=[
20+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('status', models.IntegerField(default=1)),
22+
('master', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='master.master')),
23+
('testing', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='testing.testing')),
24+
],
25+
),
26+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 3.2.9 on 2021-11-14 03:54
2+
3+
from django.db import migrations, models
4+
import django.utils.timezone
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('analytics', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='analytics',
16+
name='timestamp',
17+
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
18+
preserve_default=False,
19+
),
20+
]

apps/analytics/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

apps/analytics/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.db import models
2+
from apps.master.models import Master
3+
from apps.testing.models import Testing
4+
5+
# Create your models here.
6+
class Analytics(models.Model):
7+
8+
master = models.ForeignKey(Master, on_delete=models.CASCADE)
9+
timestamp = models.DateTimeField(auto_now_add = True)
10+
testing = models.OneToOneField(Testing, on_delete=models.CASCADE)
11+
status = models.IntegerField(default=1)
12+

apps/analytics/serializers.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from rest_framework import serializers
2+
from apps.testing.serializers import TestSerializer
3+
from apps.master.serializers import FileSerializer
4+
from .models import Analytics
5+
6+
class AnalyticsSerializer(serializers.ModelSerializer):
7+
master = FileSerializer()
8+
testing = TestSerializer()
9+
10+
class Meta:
11+
model = Analytics
12+
fields = ['id', 'timestamp', 'master', 'testing', 'status']

apps/analytics/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

apps/analytics/urls.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import path
2+
from .views import analytics, analytics_detail
3+
4+
analytics_urlpatterns = [
5+
path('analytics', analytics, name='analytics'),
6+
path('analytics/<int:pk>', analytics_detail, name="analytics-detail")
7+
8+
]

apps/analytics/views.py

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
from .models import Analytics
2+
from rest_framework.decorators import api_view
3+
from django.conf import settings
4+
from rest_framework.response import Response
5+
from rest_framework import status
6+
from .serializers import AnalyticsSerializer
7+
8+
import pandas as pd
9+
import numpy as np
10+
11+
@api_view(['GET', 'POST'])
12+
def analytics(request):
13+
if request.method == 'POST':
14+
file_serializer = AnalyticsSerializer(data=request.data)
15+
if file_serializer.is_valid():
16+
file_serializer.save()
17+
return Response(file_serializer.data, status=status.HTTP_201_CREATED)
18+
else:
19+
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
20+
21+
elif request.method == "GET":
22+
analytics = Analytics.objects.all()
23+
serializer = AnalyticsSerializer(analytics, many=True)
24+
return Response(serializer.data)
25+
26+
@api_view(['DELETE', 'PUT', 'GET'])
27+
def analytics_detail(request, pk):
28+
try:
29+
analytics = Analytics.objects.get(pk=pk)
30+
except Analytics.DoesNotExist:
31+
return Response(status=status.HTTP_404_NOT_FOUND)
32+
33+
if request.method == 'PUT':
34+
master_path = settings.SERVER_URL+ settings.MEDIA_URL + str(analytics.master.file)
35+
testing_path = settings.SERVER_URL+ settings.MEDIA_URL + str(analytics.testing.file)
36+
if request.data['format'] == 1:
37+
topdata = analyzepagetopdata(master_path, testing_path)
38+
elif request.data['format'] == 2:
39+
topdata = analyzepagedata(master_path, testing_path)
40+
return Response(topdata, status=status.HTTP_200_OK)
41+
42+
43+
def calculatetotal(masterdf, codenumber):
44+
codedata=masterdf.iloc[:,codenumber+2]
45+
featuredata=masterdf.iloc[:,1]
46+
i=0
47+
count=0
48+
while i<masterdf.shape[0]:
49+
if featuredata[i] is not np.nan:
50+
if codedata[i] is not np.nan:
51+
count+=1
52+
i+=1
53+
else:
54+
i+=1
55+
while i<masterdf.shape[0] and featuredata[i] is np.nan:
56+
if codedata[i] is not np.nan:
57+
count+=1
58+
i+=1
59+
break
60+
i+=1
61+
else:
62+
i+=1
63+
return count*100
64+
def calculatemathcing(masterdf,testdf,masternumber,testnumber):
65+
masterdata=masterdf.iloc[:,masternumber+2]
66+
testdata=testdf.iloc[:,testnumber+2]
67+
featuredata=testdf.iloc[:,1]
68+
count=0.0
69+
i=1
70+
while i<testdf.shape[0]:
71+
if testdata[i] is not np.nan and masterdata[i-1] is not np.nan:
72+
templist=str(masterdata[i-1]).split(', ', 1)
73+
if str(testdata[i]).rstrip() == templist[0]:
74+
tcount=int(templist[1])
75+
tnum=1
76+
i+=1
77+
while i<testdf.shape[0] and featuredata[i] is np.nan:
78+
if testdata[i] is not np.nan and masterdata[i-1] is not np.nan:
79+
templist=str(masterdata[i-1]).split(', ', 1)
80+
if testdata[i].rstrip() == templist[0]:
81+
tcount+=int(templist[1])
82+
tnum+=1
83+
i+=1
84+
count+=float(tcount/tnum)
85+
else:
86+
i+=1
87+
else: i+=1
88+
return count
89+
90+
def analyze(masterdf, testdf):
91+
result=[]
92+
for i in range(1, testdf.shape[1]-2, 1):
93+
templist={}
94+
for j in range(1, masterdf.shape[1]-2, 1):
95+
temp=float(calculatemathcing(masterdf,testdf,j,i)/calculatetotal(masterdf,j))*100
96+
if(temp>=100.0):
97+
temp=99.9
98+
templist.append(str(temp)[0:4]+'%')
99+
result.append(templist)
100+
return result
101+
102+
def analyzepagedata(masterpath, testpath):
103+
masterdata = pd.read_excel(masterpath)
104+
masterdf=pd.DataFrame(masterdata)
105+
testdata = pd.read_excel(testpath)
106+
testdf=pd.DataFrame(testdata)
107+
newcolumns=[]
108+
list_dictionary=[]
109+
newindex=[]
110+
newcolumns.append('Sl No')
111+
for i in range(0, testdf.shape[1]-3,1):
112+
newindex.append(testdf.columns[3:][i])
113+
for i in range(0, masterdf.shape[1]-3,1):
114+
newcolumns.append(masterdf.columns[3:][i])
115+
for i in range(1, testdf.shape[1]-2, 1):
116+
templist=[]
117+
templist.append(newindex[i-1])
118+
for j in range(1, masterdf.shape[1]-2, 1):
119+
temp=float(calculatemathcing(masterdf,testdf,j,i)/calculatetotal(masterdf,j))*100
120+
if(temp>=100.0):
121+
temp=99.9
122+
templist.append(str(temp)[0:4]+'%')
123+
templist_dictionary=dict(zip(newcolumns, templist))
124+
list_dictionary.append(templist_dictionary)
125+
return list_dictionary
126+
# analyze(masterdf, testdf)
127+
# analyzepagedata(masterpath, testpath)
128+
def getanalyzedata(masterpath, testpath):
129+
masterdata = pd.read_excel(masterpath)
130+
masterdf=pd.DataFrame(masterdata)
131+
testdata = pd.read_excel(testpath)
132+
testdf=pd.DataFrame(testdata)
133+
newindex=[]
134+
newcolumns=[]
135+
for i in range(0, testdf.shape[1]-3,1):
136+
newindex.append(testdf.columns[3:][i])
137+
for i in range(0, masterdf.shape[1]-3,1):
138+
newcolumns.append(masterdf.columns[3:][i])
139+
analyzedata=analyze(masterdf, testdf)
140+
excelanalyzedata=pd.DataFrame(analyzedata, columns=newcolumns, index=newindex)
141+
excelanalyzedata.to_excel(r'E:\PythonDjango\NewOutput2.xlsx', sheet_name='Sheet1')
142+
143+
#getanalyzedata(masterpath, testpath) // this is the second result output
144+
145+
def analyzetop(masterdf, testdf):
146+
topresult=[]
147+
toprank=[]
148+
result=[]
149+
finalresult=[]
150+
for i in range(1, testdf.shape[1]-2, 1):
151+
templist=[]
152+
toptemplist=[]
153+
tempranklist=[]
154+
topranklist=[]
155+
finaltemplist=[]
156+
for j in range(1, masterdf.shape[1]-2,1):
157+
temp=float(calculatemathcing(masterdf,testdf,j,i)/calculatetotal(masterdf,j))*100
158+
if(temp>=100.0):
159+
temp=99.9
160+
templist.append(temp)
161+
tempranklist.append(j)
162+
result.append(templist)
163+
for j in range(0, masterdf.shape[1]-4,1):
164+
for k in range(j+1,masterdf.shape[1]-3,1):
165+
if templist[j]<templist[k]:
166+
temp=templist[j]
167+
templist[j]=templist[k]
168+
templist[k]=temp
169+
temp=tempranklist[j]
170+
tempranklist[j]=tempranklist[k]
171+
tempranklist[k]=temp
172+
for j in range(0,5):
173+
toptemplist.append(templist[j])
174+
topranklist.append(tempranklist[j])
175+
finaltemplist.append('Code '+str(tempranklist[j]))
176+
finaltemplist.append(str(templist[j])[0:4]+'%')
177+
finaltemplist.extend(testdf.iloc[:,i+2][1:])
178+
topresult.append(toptemplist)
179+
toprank.append(topranklist)
180+
finalresult.append(finaltemplist)
181+
return finalresult
182+
183+
def analyzepagetopdata(masterpath, testpath):
184+
masterdata = pd.read_excel(masterpath)
185+
masterdf=pd.DataFrame(masterdata)
186+
testdata = pd.read_excel(testpath)
187+
testdf=pd.DataFrame(testdata)
188+
list_dictionary=[]
189+
newcolumns=[]
190+
for i in range(0, testdf.shape[1],1):
191+
newcolumns.append(testdf.columns[i])
192+
analyzetopdata=analyzetop(masterdf, testdf)
193+
newfirst=['','','','','','','','','','']
194+
newthird=['','','','','','','','','','']
195+
newsecond=['Code match-1', 'Code match-1%', 'Code match-2', 'Code match-2%', 'Code match-3', 'Code match-3%', 'Code match-4', 'Code match-4%', 'Code match-5', 'Code match-5%']
196+
newfirst.extend(testdf.iloc[:,0][1:])
197+
newsecond.extend(testdf.iloc[:,1][1:])
198+
newthird.extend(testdf.iloc[:,2][1:])
199+
newtopdata=[newfirst, newsecond, newthird]
200+
newtopdata.extend(analyzetopdata)
201+
for i in range(0, testdf.shape[0]+9,1):
202+
templist=[]
203+
for j in range(0, testdf.shape[1], 1):
204+
if(newtopdata[j][i] is not np.nan):
205+
templist.append(newtopdata[j][i])
206+
else:
207+
templist.append('')
208+
templist_dictionary=dict(zip(newcolumns, templist))
209+
list_dictionary.append(templist_dictionary)
210+
return list_dictionary

apps/master/__init__.py

Whitespace-only changes.
157 Bytes
Binary file not shown.
896 Bytes
Binary file not shown.
441 Bytes
Binary file not shown.
894 Bytes
Binary file not shown.
Binary file not shown.
436 Bytes
Binary file not shown.
1.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)