-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearng_al.py
More file actions
2373 lines (2090 loc) · 144 KB
/
learng_al.py
File metadata and controls
2373 lines (2090 loc) · 144 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/Users/abhinav/Anaconda2/python
# -*- coding: utf-8 -*-
"""
Created on Wed May 24 13:33:12 2017
@author: abhinav
"""
import numpy
import mysql.connector
import json
import pandas as pd
import sys
import matplotlib.pyplot as plt
"""
try:
data=sys.argv[1]
except:
print "ERROR"
print data
d=json.loads(data)
print d
print d['1']
#raw_input()
with open('Python_input.json') as json_data:
d = json.load(json_data)
print d
d = map(int, d)
"""
data = 2
data1 = 3
d1 = int(data)
d2 = int(data1)
#print data1
mathop = d1
Ques_Threshold = 9999999
Count_Threshold = 3
selectlvl = [d2]
n_lvl_val = 0
#Total_No_Wrongs = 50
List_Wrongs = pd.DataFrame([0])
#print selectlvl
def operator_miss(df1,df2,length):
df1_new = pd.DataFrame([0])
#print df1
for lvl_basd_perf in xrange(0,len(df1.index)):
if (df1.ix[lvl_basd_perf,"selectedLevel"] == selectlvl[0]):
df1_new = df1_new.append(df1.ix[[lvl_basd_perf]])
df1_new = df1_new.drop(0,0)
df1_new = df1_new.drop(0,1).reset_index(drop=1)
#print "Iam printhing the new dataframe"
#print df1_new
for i in xrange(0,len(df1_new.index)):
if(~(df1_new.ix[i,'userAnswer'] != df1_new.ix[i,'Addition_Ans']) and df1_new.ix[i,'mathOperator'] != 1):
df2.ix[i,'Match_Case'] = 1
df2.ix[i,'questionPair_left'] = df1_new.ix[i,'questionPair_left']
df2.ix[i,'questionPair_right'] = df1_new.ix[i,'questionPair_right']
elif(~(df1_new.ix[i,'userAnswer'] != df1_new.ix[i,'Substraction_Ans']) and df1_new.ix[i,'mathOperator'] != 2):
df2.ix[i,'Match_Case'] = 2
df2.ix[i,'questionPair_left'] = df1_new.ix[i,'questionPair_left']
df2.ix[i,'questionPair_right'] = df1_new.ix[i,'questionPair_right']
elif(~(df1_new.ix[i,'userAnswer'] != df1_new.ix[i,'Multiplication_Ans']) and df1_new.ix[i,'mathOperator'] != 3):
df2.ix[i,'Match_Case'] = 3
df2.ix[i,'questionPair_left'] = df1_new.ix[i,'questionPair_left']
df2.ix[i,'questionPair_right'] = df1_new.ix[i,'questionPair_right']
elif(~(df1_new.ix[i,'userAnswer'] != df1_new.ix[i,'Division_Ans']) and df1_new.ix[i,'mathOperator'] != 4):
df2.ix[i,'Match_Case'] = 4
df2.ix[i,'questionPair_left'] = df1_new.ix[i,'questionPair_left']
df2.ix[i,'questionPair_right'] = df1_new.ix[i,'questionPair_right']
else:
df2.ix[i,'Match_Case'] = 0
df2 = df2.drop(0, 1)
#print df2
return df2
def missentry(df_train,unintentional_df):
#unintentional_df = pd.DataFrame(['Match_Case'])
for j in xrange(0,len(df_train.index)):
if ((df_train.ix[j,'userAnswer'] == 99779977 or df_train.ix[j,'userAnswer'] == 99889988) or df_train.ix[j,'questionDurationinS'] <= 1.000):
unintentional_df.ix[j,'Match_Case'] = 1
unintentional_df.ix[j,'questionPair_left'] = df_train.ix[j,'questionPair_left']
unintentional_df.ix[j,'questionPair_right'] = df_train.ix[j,'questionPair_right']
unintentional_df.ix[j,'mathOperator'] = df_train.ix[j,'mathOperator']
unintentional_df.ix[j,'questionDurationinS'] = df_train.ix[j,'questionDurationinS']
unintentional_df.ix[j,'userAnswer'] = df_train.ix[j,'userAnswer']
else:
unintentional_df.ix[j,'Match_Case'] = 0
unintentional_df = unintentional_df.drop(0,1)
return unintentional_df
def weights(Total_Wrongs,Total_Wrong_Count,weight_result_df):
#print Total_Wrong_Count
#print Total_Wrongs
for wrg_val in xrange(0,len(Total_Wrongs.index)):
for x in xrange(0,len(Total_Wrong_Count.index)):
if(Total_Wrongs.ix[wrg_val,"level"] == Total_Wrong_Count.ix[x,"selectedLevel"]):
weight_result_df.ix[x,'Questions'] = Total_Wrong_Count.ix[x,'Questions']
weight_result_df.ix[x,'weights(%)'] = (Total_Wrong_Count.ix[x,'Total_Frequency']/Total_Wrongs.ix[wrg_val,"Wrongs"])*100
weight_result_df.ix[x,'Total_Frequency'] = Total_Wrong_Count.ix[x,"Total_Frequency"]
weight_result_df.ix[x,'Total_No_Wrongs'] = Total_Wrongs.ix[wrg_val,"Wrongs"]
weight_result_df.ix[x,'SelectedLevel'] = Total_Wrongs.ix[wrg_val,"level"]
weight_result_df = weight_result_df.drop(0,1)
#print weight_result_df
return weight_result_df
def count_questions_fun(my_list_2,extended_my_list,selectlvl,List_Wrongs):
#print my_list_2
for row in xrange(0,len(my_list_2)):
if ((my_list_2.ix[row,'mathOperator']) == mathop):
extended_my_list = (extended_my_list.append(my_list_2.ix[[row]],ignore_index=True))
#print extended_my_list
extended_my_list =extended_my_list.drop(0,1)
extended_my_list =extended_my_list.drop(0,0).reset_index(drop=1)
extended_my_list['questionPair_left'], extended_my_list['questionPair_right'] = zip(*extended_my_list['questionPair'].map(lambda x: x.split(',')))
extended_my_list =extended_my_list.drop('questionPair',axis=1)
extended_my_list[['questionPair_left', 'questionPair_right']] = extended_my_list[['questionPair_left', 'questionPair_right']].astype(int)
extended_my_list = extended_my_list.apply(pd.to_numeric)
temp1 = 0
#print temp1
for lvl_val in range(len(selectlvl)):
final_extended_my_list = pd.DataFrame([0])
for new_row in xrange(0,len(extended_my_list)):
if ((extended_my_list.ix[new_row,'selectedLevel']) == selectlvl[lvl_val]):
final_extended_my_list = (final_extended_my_list.append(extended_my_list.ix[[new_row]],ignore_index=True))
#print final_extended_my_list
final_extended_my_list =final_extended_my_list.drop(0,0).reset_index(drop=1)
#print final_extended_my_list
Total_Wrongs = len(final_extended_my_list)
List_Wrongs.ix[temp1,'level'] = selectlvl[lvl_val]
List_Wrongs.ix[temp1,'Wrongs'] = Total_Wrongs
temp1= temp1 + 1
final_extended_my_list =final_extended_my_list.drop(final_extended_my_list.index,inplace=True)
#final_extended_my_list = final_extended_my_list.drop(0,1)
#print final_extended_my_list
#List_Wrongs =List_Wrongs.drop(0,0).reset_index(drop=1)
List_Wrongs = List_Wrongs.drop(0,1)
#print List_Wrongs
return List_Wrongs
def add_sub_analysis_lvl_4(lvl_data_df):
#print lvl_data_df
new_final_extended_my_list = pd.DataFrame([0])
new_df_1 = pd.DataFrame()
new_df_2 = pd.DataFrame([0])
new_count_1 = pd.DataFrame()
new_count_2 = pd.DataFrame()
new_count_1_df2 = pd.DataFrame()
new_count_1_df2 = pd.DataFrame()
#print lvl_data_df
#print temp_updated_df_train
for row in xrange(0,len(lvl_data_df)):
if((lvl_data_df.ix[row,"questionPair_right"]) <=9 and (lvl_data_df.ix[row,"selectedLevel"]) == 4 and selectlvl[0] == 4):
new_final_extended_my_list = (new_final_extended_my_list.append(lvl_data_df.ix[[row]],ignore_index=True))
elif((lvl_data_df.ix[row,"selectedLevel"])==4 and selectlvl[0] == 4):
new_df_2 = new_df_2.append(lvl_data_df.ix[[row]],ignore_index=True)
else:
break
new_final_extended_my_list =new_final_extended_my_list.drop(0,1)
new_final_extended_my_list =new_final_extended_my_list.drop(0,0).reset_index(drop=1)
new_df_2 =new_df_2.drop(0,1)
new_df_2 =new_df_2.drop(0,0).reset_index(drop=1)
"""
The questions of type where left_question>9 and right_question>9 are analysed and
the frequecies are calculated in the below code.
"""
if (len(new_final_extended_my_list.index) != 0):
new_df_1 = new_final_extended_my_list.copy()
#print new_df_1
new_df_1 = new_df_1[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1 = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2 = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1 = new_count_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2 = new_count_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1 = new_count_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2 = new_count_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_1
#print new_count_2
#print new_temp_count
#new_final_extended_my_list = new_final_extended_my_list.groupby(['selectedLevel','questionPair_left','questionPair_right','mathOperator']).size().reset_index()
#new_val_22 = ((count_val/len(lvl_data_df.index))*100)
#new_df_2 =new_df_2.drop(0,1)
#new_df_2 =new_df_2.drop(0,0).reset_index(drop=1)
"""
Analysing the second dataframe questions saved in new_df_2
"""
if (len(new_df_2.index) != 0):
new_df_2 = new_df_2[[4,5,6,7]]
#print "This is df3"
#print new_df_3
new_temp_count_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_df2 = new_count_1_df2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_df2 = new_count_2_df2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_df2 = new_count_1_df2.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_df2 = new_count_2_df2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_1_df3
#print new_count_2_df3
#print new_temp_count_df3
count_val = len(new_final_extended_my_list)
count_val = float(count_val)
#print count_val
#print new_val_22
#print new_final_extended_my_list
#print new_df_1
#new_count_1 = new_count_1[[0,1,2,3]].sort_values(by=['Count_As_Left_Question','Operator','Questions'], ascending=[False,False,False])
#if(len(new_df_1.index) != 0 and len(new_df_2) !=0 ):
#print new_count_2_df2
return new_count_1,new_count_2,new_df_1,new_count_1_df2,new_count_2_df2,new_df_2
"""
elif(len(new_df_1.index) == 0 and len(new_df_2) !=0 ):
return new_count_1_df2,new_count_2_df2,new_df_2
elif(len(new_df_1.index) != 0 and len(new_df_2) ==0 ):
return new_count_1,new_count_2,new_df_1
else:
return 0
"""
"""
for row_2 in xrange(0,len(new_df_2)):
if ((new_df_2.ix[row_2,"questionPair_left"<=9] and new_df_2.ix[row_2,"questionPair_left"<=9]))
print new_df_2.ix[row_2,"questionPair_left"<=9]
#print new_final_extended_my_list
#print lvl_data_df
"""
def add_sub_analysis_lvl_3(lvl_data_df):
#print lvl_data_df
new_final_extended_my_list = pd.DataFrame([0])
new_df_1 = pd.DataFrame()
new_df_2 = pd.DataFrame([0])
new_count_1 = pd.DataFrame()
new_count_2 = pd.DataFrame()
new_count_1_df2 = pd.DataFrame()
new_count_2_df2 = pd.DataFrame()
#print lvl_data_df
#print temp_updated_df_train
for row in xrange(0,len(lvl_data_df)):
if((lvl_data_df.ix[row,"questionPair_right"]) <= 9 and (lvl_data_df.ix[row,"selectedLevel"]) == 3 and selectlvl[0] == 3):
new_final_extended_my_list = (new_final_extended_my_list.append(lvl_data_df.ix[[row]],ignore_index=True))
elif((lvl_data_df.ix[row,"selectedLevel"])==3 and selectlvl[0] == 3):
new_df_2 = new_df_2.append(lvl_data_df.ix[[row]],ignore_index=True)
else:
break
new_final_extended_my_list =new_final_extended_my_list.drop(0,1)
new_final_extended_my_list =new_final_extended_my_list.drop(0,0).reset_index(drop=1)
new_df_2 =new_df_2.drop(0,1)
new_df_2 =new_df_2.drop(0,0).reset_index(drop=1)
"""
The questions of type where left_question>9 and right_question>9 are analysed and
the frequecies are calculated in the below code.
"""
if (len(new_final_extended_my_list.index) != 0):
new_df_1 = new_final_extended_my_list.copy()
#print new_df_1
new_df_1 = new_df_1[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1 = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2 = new_df_1.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1 = new_count_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2 = new_count_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1 = new_count_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2 = new_count_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_1
#print new_count_2
#print new_temp_count
#new_final_extended_my_list = new_final_extended_my_list.groupby(['selectedLevel','questionPair_left','questionPair_right','mathOperator']).size().reset_index()
#new_val_22 = ((count_val/len(lvl_data_df.index))*100)
#new_df_2 =new_df_2.drop(0,1)
#new_df_2 =new_df_2.drop(0,0).reset_index(drop=1)
"""
Analysing the second dataframe questions saved in new_df_2
"""
if (len(new_df_2.index) != 0):
new_df_2 = new_df_2[[4,5,6,7]]
#print "This is df3"
#print new_df_3
new_temp_count_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_df2 = new_df_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_df2 = new_count_1_df2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_df2 = new_count_2_df2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_df2 = new_count_1_df2.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_df2 = new_count_2_df2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_1_df3
#print new_count_2_df3
#print new_temp_count_df3
count_val = len(new_final_extended_my_list)
count_val = float(count_val)
#print count_val
#print new_val_22
#print new_final_extended_my_list
#print new_df_1
#new_count_1 = new_count_1[[0,1,2,3]].sort_values(by=['Count_As_Left_Question','Operator','Questions'], ascending=[False,False,False])
#if(len(new_df_1.index) != 0 and len(new_df_2) !=0 ):
return new_count_1,new_count_2,new_df_1,new_count_1_df2,new_count_2_df2,new_df_2
"""
elif(len(new_df_1.index) == 0 and len(new_df_2) !=0 ):
return new_count_1_df2,new_count_2_df2,new_df_2
elif(len(new_df_1.index) != 0 and len(new_df_2) ==0 ):
return new_count_1,new_count_2,new_df_1
else:
return 0
"""
"""
for row_2 in xrange(0,len(new_df_2)):
if ((new_df_2.ix[row_2,"questionPair_left"<=9] and new_df_2.ix[row_2,"questionPair_left"<=9]))
print new_df_2.ix[row_2,"questionPair_left"<=9]
#print new_final_extended_my_list
#print lvl_data_df
"""
def add_sub_analysis_lvl_2(lvl_data_df):
new_final_extended_my_list_lvl_2 = pd.DataFrame([0])
new_df_1_lvl_2 = pd.DataFrame([0])
new_df_2_lvl_2 = pd.DataFrame([0])
new_count_1_lvl_2 = pd.DataFrame()
new_count_2_lvl_2 = pd.DataFrame()
new_count_1_lvl_2_1 = pd.DataFrame()
new_count_2_lvl_2_2 = pd.DataFrame()
#print lvl_data_df
#print temp_updated_df_train
for row in xrange(0,len(lvl_data_df)):
if((lvl_data_df.ix[row,"questionPair_right"]) <= 9 and (lvl_data_df.ix[row,"selectedLevel"]) ==2 and selectlvl[0] == 2):
new_final_extended_my_list_lvl_2 = (new_final_extended_my_list_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True))
elif(lvl_data_df.ix[row,"selectedLevel"]==2 and selectlvl[0] == 2):
new_df_2_lvl_2 = new_df_2_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True)
else:
break
new_final_extended_my_list_lvl_2 =new_final_extended_my_list_lvl_2.drop(0,1)
new_final_extended_my_list_lvl_2 =new_final_extended_my_list_lvl_2.drop(0,0).reset_index(drop=1)
new_df_2_lvl_2 =new_df_2_lvl_2.drop(0,1)
new_df_2_lvl_2 =new_df_2_lvl_2.drop(0,0).reset_index(drop=1)
#print "chking the dataframe values !!!!!!!!!!!!!!!!!!!!!!!!!!!!"
#print new_final_extended_my_list_lvl_2
#print new_df_2_lvl_2
if (len(new_final_extended_my_list_lvl_2.index) != 0):
new_df_1_lvl_2 = new_final_extended_my_list_lvl_2.copy()
#print new_df_2_lvl_2
new_df_1_lvl_2 = new_df_1_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_lvl_2 = new_count_1_lvl_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_lvl_2 = new_count_2_lvl_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_lvl_2 = new_count_1_lvl_2.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_lvl_2 = new_count_2_lvl_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_val_22
#print new_final_extended_my_list
#print new_df_1
if (len(new_df_2_lvl_2.index) != 0):
new_df_2_lvl_2 = new_df_2_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count_lvl_2 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_lvl_2_1 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_lvl_2_2 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_lvl_2_1 = new_count_1_lvl_2_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_lvl_2_2 = new_count_2_lvl_2_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_lvl_2_1 = new_count_1_lvl_2_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_lvl_2_2 = new_count_2_lvl_2_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_2_lvl_2_2
#print new_count_1_lvl_2_1
#print new_df_2_lvl_2
#if(len(new_df_1_lvl_2.index) != 0 and len(new_df_2_lvl_2) !=0 ):
return new_count_1_lvl_2,new_count_2_lvl_2,new_df_1_lvl_2,new_count_1_lvl_2_1,new_count_2_lvl_2_2,new_df_2_lvl_2
"""
elif(len(new_df_1_lvl_2.index) == 0 and len(new_df_2_lvl_2) !=0 ):
return new_count_1_lvl_2_1,new_count_2_lvl_2_2,new_df_2_lvl_2
elif(len(new_df_1_lvl_2.index) != 0 and len(new_df_2_lvl_2) ==0 ):
return new_count_1_lvl_2,new_count_2_lvl_2,new_df_1_lvl_2
else:
return 0
"""
def add_analysis_lvl_2(lvl_data_df):
new_final_extended_my_list_lvl_2 = pd.DataFrame([0])
new_df_1_lvl_2 = pd.DataFrame([0])
new_df_2_lvl_2 = pd.DataFrame([0])
new_df_3_lvl_2 = pd.DataFrame([0])
new_df_4_lvl_2 = pd.DataFrame([0])
new_count_1_lvl_2 = pd.DataFrame()
new_count_2_lvl_2 = pd.DataFrame()
new_count_1_lvl_2_1 = pd.DataFrame()
new_count_2_lvl_2_2 = pd.DataFrame()
counts_ty3_lvl2_1 = pd.DataFrame()
counts_ty3_lvl2_2 = pd.DataFrame()
counts_ty4_lvl2_1 = pd.DataFrame()
counts_ty4_lvl2_2 = pd.DataFrame()
#print lvl_data_df
#print temp_updated_df_train
for row in xrange(0,len(lvl_data_df)):
if((lvl_data_df.ix[row,"questionPair_left"]) > 9 and (lvl_data_df.ix[row,"questionPair_right"]) <= 9 and (lvl_data_df.ix[row,"selectedLevel"]) ==2 and selectlvl[0] == 2):
new_final_extended_my_list_lvl_2 = (new_final_extended_my_list_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True))
elif((lvl_data_df.ix[row,"questionPair_left"]) <= 9 and (lvl_data_df.ix[row,"questionPair_right"]) > 9 and (lvl_data_df.ix[row,"selectedLevel"]) ==2 and selectlvl[0] == 2):
new_df_2_lvl_2 = new_df_2_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True)
elif((lvl_data_df.ix[row,"questionPair_left"]) <= 9 and (lvl_data_df.ix[row,"questionPair_right"]) <= 9 and (lvl_data_df.ix[row,"selectedLevel"]) ==2 and selectlvl[0] == 2):
new_df_3_lvl_2 = new_df_3_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True)
elif((lvl_data_df.ix[row,"questionPair_left"]) > 9 and (lvl_data_df.ix[row,"questionPair_right"]) > 9 and (lvl_data_df.ix[row,"selectedLevel"]) ==2 and selectlvl[0] == 2):
new_df_4_lvl_2 = new_df_4_lvl_2.append(lvl_data_df.ix[[row]],ignore_index=True)
else:
break
new_final_extended_my_list_lvl_2 =new_final_extended_my_list_lvl_2.drop(0,1)
new_final_extended_my_list_lvl_2 =new_final_extended_my_list_lvl_2.drop(0,0).reset_index(drop=1)
new_df_4_lvl_2 =new_df_4_lvl_2.drop(0,1)
new_df_4_lvl_2 =new_df_4_lvl_2.drop(0,0).reset_index(drop=1)
new_df_2_lvl_2 =new_df_2_lvl_2.drop(0,1)
new_df_2_lvl_2 =new_df_2_lvl_2.drop(0,0).reset_index(drop=1)
new_df_3_lvl_2 =new_df_3_lvl_2.drop(0,1)
new_df_3_lvl_2 =new_df_3_lvl_2.drop(0,0).reset_index(drop=1)
if (len(new_final_extended_my_list_lvl_2.index) != 0):
#print "!!!!!!!!!!!!!!!!!!!!!This is Typ-0 DataFrame!!!!!!!!!!!!!!!!!!!!!!"
#print new_final_extended_my_list_lvl_2
new_df_1_lvl_2 = new_final_extended_my_list_lvl_2.copy()
#print new_df_2_lvl_2
new_df_1_lvl_2 = new_df_1_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
if (len(new_df_1_lvl_2) != 0):
new_temp_count_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_lvl_2 = new_df_1_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_lvl_2 = new_count_1_lvl_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_lvl_2 = new_count_2_lvl_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_lvl_2 = new_count_1_lvl_2.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_lvl_2 = new_count_2_lvl_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_val_22
#print new_final_extended_my_list
#print new_df_1
if (len(new_df_2_lvl_2.index) != 0):
#print "!!!!!!!!!!!!!!!!!!!!!This is Typ-1 DataFrame!!!!!!!!!!!!!!!!!!!!!!"
#print new_df_2_lvl_2
new_df_2_lvl_2 = new_df_2_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count_lvl_2 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_lvl_2_1 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_lvl_2_2 = new_df_2_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_lvl_2_1 = new_count_1_lvl_2_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_lvl_2_2 = new_count_2_lvl_2_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_lvl_2_1 = new_count_1_lvl_2_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_lvl_2_2 = new_count_2_lvl_2_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_2_lvl_2_2
#print new_count_1_lvl_2_1
#print new_df_2_lvl_2
if (len(new_df_3_lvl_2.index) != 0):
#print "!!!!!!!!!!!!!!!!!!!!!This is Typ-2 DataFrame!!!!!!!!!!!!!!!!!!!!!!"
#print new_df_3_lvl_2
new_df_3_lvl_2 = new_df_3_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_tot_typ3_count = new_df_3_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
counts_ty3_lvl2_1 = new_df_3_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
counts_ty3_lvl2_2 = new_df_3_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
counts_ty3_lvl2_1 = counts_ty3_lvl2_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
counts_ty3_lvl2_2 = counts_ty3_lvl2_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
counts_ty3_lvl2_1 = counts_ty3_lvl2_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
counts_ty3_lvl2_2 = counts_ty3_lvl2_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_2_lvl_2_2
#print new_count_1_lvl_2_1
#print new_df_2_lvl_2
if (len(new_df_4_lvl_2.index) != 0):
#print "!!!!!!!!!!!!!!!!!!!!!This is Typ-3 DataFrame!!!!!!!!!!!!!!!!!!!!!!"
#print new_df_4_lvl_2
new_df_4_lvl_2 = new_df_4_lvl_2[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_tot_typ4_count = new_df_4_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
counts_ty4_lvl2_1 = new_df_4_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
counts_ty4_lvl2_2 = new_df_4_lvl_2.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
counts_ty4_lvl2_1 = counts_ty4_lvl2_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
counts_ty4_lvl2_2 = counts_ty4_lvl2_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
counts_ty4_lvl2_1 = counts_ty4_lvl2_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
counts_ty4_lvl2_2 = counts_ty4_lvl2_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_count_2_lvl_2_2
#print new_count_1_lvl_2_1
#print new_df_2_lvl_2
#if(len(new_df_1_lvl_2.index) != 0 and len(new_df_2_lvl_2) !=0 ):
return new_count_1_lvl_2,new_count_2_lvl_2,new_df_1_lvl_2,new_count_1_lvl_2_1,new_count_2_lvl_2_2,new_df_2_lvl_2,counts_ty3_lvl2_1,counts_ty3_lvl2_2,new_df_3_lvl_2,counts_ty4_lvl2_1,counts_ty4_lvl2_2,new_df_4_lvl_2
"""
elif(len(new_df_1_lvl_2.index) == 0 and len(new_df_2_lvl_2) !=0 ):
return new_count_1_lvl_2_1,new_count_2_lvl_2_2,new_df_2_lvl_2
elif(len(new_df_1_lvl_2.index) != 0 and len(new_df_2_lvl_2) ==0 ):
return new_count_1_lvl_2,new_count_2_lvl_2,new_df_1_lvl_2
else:
return 0
"""
def add_sub_analysis_lvl_1(lvl_data_df):
#new_final_extended_my_list = pd.DataFrame([0])
new_df_1_lvl_1= pd.DataFrame([0])
#print lvl_data_df
#print temp_updated_df_train
for row in xrange(0,len(lvl_data_df)):
if((lvl_data_df.ix[row,"questionPair_right"]) <= 9 and (lvl_data_df.ix[row,"selectedLevel"])==1 and selectlvl[0] == 1):
new_df_1_lvl_1 = (new_df_1_lvl_1.append(lvl_data_df.ix[[row]],ignore_index=True))
else:
break
new_df_1_lvl_1 =new_df_1_lvl_1.drop(0,1)
new_df_1_lvl_1 =new_df_1_lvl_1.drop(0,0).reset_index(drop=1)
new_df_1_lvl_1 = new_df_1_lvl_1[[4,5,6,7]]
#print "This is df1"
#print new_df_1
new_temp_count = new_df_1_lvl_1.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
new_count_1_lvl_1 = new_df_1_lvl_1.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
new_count_2_lvl_1 = new_df_1_lvl_1.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
new_count_1_lvl_1 = new_count_1_lvl_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_2_lvl_1 = new_count_2_lvl_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
new_count_1_lvl_1 = new_count_1_lvl_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
new_count_2_lvl_1 = new_count_2_lvl_1.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print new_val_22
#print new_final_extended_my_list
#print new_df_1
return new_count_1_lvl_1,new_count_2_lvl_1,new_df_1_lvl_1
def mul_analy_fun(mul_df):
mul_df = mul_df[[4,5,6,7]]
#print mul_df
mul_new_temp = mul_df.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
mul_new_count_1 = mul_df.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
mul_new_count_2 = mul_df.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
mul_new_count_1 = mul_new_count_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
mul_new_count_2 = mul_new_count_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
mul_new_count_1 = mul_new_count_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
mul_new_count_2 = mul_new_count_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print mul_new_count_1
#print mul_new_count_2
#print new_df_1
return mul_new_count_1,mul_new_count_2,mul_df
def div_analy_fun(div_df):
div_df = div_df[[4,5,6,7]]
#print mul_df
div_new_temp = div_df.groupby(['selectedLevel','mathOperator','questionPair_left','questionPair_right']).size().to_frame('size').reset_index()
div_new_count_1 = div_df.groupby(['selectedLevel','mathOperator','questionPair_left']).size().to_frame('size').reset_index()
div_new_count_2 = div_df.groupby(['selectedLevel','mathOperator','questionPair_right']).size().to_frame('size').reset_index()
#summ_new_count = pd.concat([new_count_1,new_count_2], axis=1).reset_index().apply(pd.to_numeric)
div_new_count_1 = div_new_count_1[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
div_new_count_2 = div_new_count_2[[0,1,2,3]].sort_values(by=['size'], ascending=[False]).reset_index(drop=1)
div_new_count_1 = div_new_count_1.rename(columns={'questionPair_left': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
div_new_count_2 = div_new_count_2.rename(columns={'questionPair_right': 'Questions', 'size': 'Total_Frequency', 'mathOperator': 'Operator'})
#print mul_new_count_1
#print mul_new_count_2
#print new_df_1
return div_new_count_1,div_new_count_2,div_df
def count_sub_lvl_3(my_sub_dataframe,selectlvl,List_Wrongs):
#print my_sub_dataframe
temp1 = 0
#print my_list_2
#print my_sub_dataframe
for lvl_val in range(len(selectlvl)):
final_extended_my_list_1 = pd.DataFrame([0])
for new_row in xrange(0,len(my_sub_dataframe)):
if ((my_sub_dataframe.ix[new_row,'selectedLevel']) == selectlvl[lvl_val]):
final_extended_my_list_1 = (final_extended_my_list_1.append(my_sub_dataframe.ix[[new_row]],ignore_index=True))
#print final_extended_my_list
final_extended_my_list_1 =final_extended_my_list_1.drop(0,0).reset_index(drop=1)
#print final_extended_my_list
Total_Wrongs = len(final_extended_my_list_1)
List_Wrongs.ix[temp1,'level'] = selectlvl[lvl_val]
List_Wrongs.ix[temp1,'Wrongs'] = Total_Wrongs
temp1= temp1 + 1
final_extended_my_list_1 =final_extended_my_list_1.drop(final_extended_my_list_1.index,inplace=True)
#final_extended_my_list = final_extended_my_list.drop(0,1)
#print final_extended_my_list
#List_Wrongs =List_Wrongs.drop(0,0).reset_index(drop=1)
List_Wrongs = List_Wrongs.drop(0,1)
#print List_Wrongs
return List_Wrongs
def php_data(new_data,weight_result_df_1_right,selectlvl):
#print "Function successfully called"
sub_return_list_1 = []
sub_return_list_2 = []
sub_return_list_3 = []
sub_return_list_4 = []
sub_return_list_5 = []
sub_return_list_6 = []
return_list = []
#print "!!!!!!!!!!!This is new_data !!!!!!!!!!!!!!!!11"
#print new_data
#print weight_result_df_1_right
x_list_sugg_questions = []
y_list_sugg_questions = []
new_data = new_data[[0,5,4,6]]
weight_result_df_1_right = weight_result_df_1_right[[0,5,4,6]]
new_data = new_data.reset_index(drop =1)
for abhi in xrange(0,len(new_data.index)):
abhi_temp_data = map( int, new_data.ix[abhi,"Suggested_Numbers"].split(','))
for jj in abhi_temp_data:
x_list_sugg_questions.append(new_data.ix[abhi,"Questions"])
y_list_sugg_questions.append(jj)
plot_x_1 = x_list_sugg_questions
plot_y_1 = y_list_sugg_questions
#print plot_x
#print plot_y
plt.plot(plot_x_1, plot_y_1, 'bo')
#plt.show()
weight_result_df_1_right = weight_result_df_1_right.reset_index(drop = 1)
for w_1 in xrange(0,len(new_data.index)):
iam_temp = new_data.ix[w_1,"Questions"]
sub_return_list_1.append(iam_temp)
sub_return_list_2.append(new_data.ix[w_1,"Right_Question_Choice"])
sub_return_list_5.append(new_data.ix[w_1,"Suggested_Numbers"])
#sub_return_list_3.append(new_data.ix[w_1,"Suggested_Numbers"])
#print sub_return_list_1
#print return_list
#print sub_return_list_2
#print weight_result_df_1_right
for w_2 in xrange(0,len(weight_result_df_1_right.index)):
iam_temp_1 = weight_result_df_1_right.ix[w_2,"Questions"]
#print iam_temp_1
sub_return_list_3.append(iam_temp_1)
sub_return_list_4.append(weight_result_df_1_right.ix[w_2,"Left_Question_Choice"])
sub_return_list_6.append(weight_result_df_1_right.ix[w_2,"Suggested_Numbers"])
return_list = [sub_return_list_1,sub_return_list_2,sub_return_list_5,sub_return_list_3,sub_return_list_4,sub_return_list_6]
#print return_list
return return_list
#return new_final_extended_my_list
"""
This part of the code is used to connect to the student database and extract the data.
"""
con = mysql.connector.connect(host='localhost',user='root',password='',db='mysql',port=3306)
cur1 = con.cursor(buffered=True)
cur2 = con.cursor(buffered=True)
cur3 = con.cursor(buffered=True)
cur4 = con.cursor(buffered=True)
cur1.execute('SELECT a.selectedLevel,a.additionProblemCount,a.additionProblemsMissed,a.subtractionProblemCount,a.subtractionProblemsMissed,a.multiplicationProblemCount,a.multiplicationProblemsMissed,a.divisionProblemCount,a.divisionProblemsMissed,a.numberofWrongs,a.numberofCorrects,a.totalNumberOfProblems,a.studentScore,a.cummulativePoints,b.questionPair,b.userAnswer,b.correctAnswer,a.problemType,a.selectedLevel,b.mathOperator,b.questionTime,b.questionDurationinS FROM a1234 as a, a1234_details as b where a.dateOfUse=b.dateOfUse and a.selectedLevel=b.selectedLevel and a.problemType=b.problemType')
cur2.execute('SELECT a.selectedLevel,a.additionProblemCount,a.additionProblemsMissed,a.subtractionProblemCount,a.subtractionProblemsMissed,a.multiplicationProblemCount,a.multiplicationProblemsMissed,a.divisionProblemCount,a.divisionProblemsMissed,a.numberofWrongs,a.numberofCorrects,a.totalNumberOfProblems,a.studentScore,a.cummulativePoints,b.questionPair,b.userAnswer,b.correctAnswer,a.problemType,a.selectedLevel,b.mathOperator,b.questionTime,b.questionDurationinS FROM m1234 as a, m1234_details as b where a.dateOfUse=b.dateOfUse and a.selectedLevel=b.selectedLevel and a.problemType=b.problemType')
cur3.execute('SELECT a.selectedLevel,a.additionProblemCount,a.additionProblemsMissed,a.subtractionProblemCount,a.subtractionProblemsMissed,a.multiplicationProblemCount,a.multiplicationProblemsMissed,a.divisionProblemCount,a.divisionProblemsMissed,a.numberofWrongs,a.numberofCorrects,a.totalNumberOfProblems,a.studentScore,a.cummulativePoints,b.questionPair,b.userAnswer,b.correctAnswer,a.problemType,a.selectedLevel,b.mathOperator,b.questionTime,b.questionDurationinS FROM ur1234 as a, ur1234_details as b where a.dateOfUse=b.dateOfUse and a.selectedLevel=b.selectedLevel and a.problemType=b.problemType')
cur4.execute('SELECT a.dateOfUse,a.studentID,a.selectedLevel,a.problemType,a.modeOfUse,a.questionTime,a.questionDurationinS,a.questionPair,a.mathOperator,a.userAnswer,a.correctAnswer FROM detail_performance as a')
try:
data1=cur1.fetchall()
data2=cur2.fetchall()
data3=cur3.fetchall()
data4=cur4.fetchall()
except mysql.connector.errors.InterfaceError as ie:
if ie.msg == 'No result set to fetch from.':
pass
else:
raise
#print data1
#print data2
#new_array_a1234 = numpy.array(data1)
#new_array_a1234_details = numpy.array(data2)
#x = new_array_a1234[:,][0:1:,],cur1.description
#print x
df_a = pd.DataFrame(data1)
df_m = pd.DataFrame(data2)
df_rn=pd.DataFrame(data3)
df_new_data = pd.DataFrame(data4)
"""
The part is oriented to change the column names of the dataframes and later
all the individual table data re being combined ofr analysis.
"""
old_names = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
new_names = ['selectedLevel','additionProblemCount','additionProblemsMissed','subtractionProblemCount','subtractionProblemsMissed','multiplicationProblemCount','multiplicationProblemsMissed','divisionProblemCount','divisionProblemsMissed','numberofWrongs','numberofCorrects','totalNumberOfProblems','studentScore','cummulativePoints','questionPair','userAnswer','correctAnswer','problemType','selectedLevel','mathOperator','questionTime','questionDurationinS']
df_a.rename(columns=dict(zip(old_names, new_names)), inplace=True)
df_m.rename(columns=dict(zip(old_names, new_names)), inplace=True)
df_rn.rename(columns=dict(zip(old_names, new_names)), inplace=True)
df_new_data_old_names = [0,1,2,3,4,5,6,7,8,9,10]
df_new_data_new_names = ['dateOfUse','studentID','selectedLevel','problemType','modeOfUse','questionTime','questionDurationinS','questionPair','mathOperator','userAnswer','correctAnswer']
df_new_data.rename(columns=dict(zip(df_new_data_old_names, df_new_data_new_names)), inplace=True)
df_new = pd.concat([df_a, df_m,df_rn],ignore_index=True)
df_train = df_new[[18,16,19,14,15,20,21,17]]
df_train_2 = df_new_data[[2,10,8,7,9,5,6,3]]
df_train = pd.concat([df_train, df_train_2],ignore_index=True)
df_train['problemType'] = df_train['problemType'].map({'Subtraction': 2, 'Random': 5,'Addition':1,'Multiplication':3,'Division':4})
df_train['mathOperator'] = df_train['mathOperator'].map({'-': 2, '+': 1,'x': 3,'/': 4,'&di':4})
#print df_train
updated_df_train = pd.DataFrame()
for val in xrange(0,len(df_train)):
if (df_train.ix[val,"mathOperator"]==mathop):
updated_df_train = updated_df_train.append(df_train.ix[[val]],ignore_index=True)
#print updated_df_train
updated_df_train[["selectedLevel"]] = updated_df_train[["selectedLevel"]].apply(pd.to_numeric)
new_temp_updt_df_train = pd.DataFrame()
for dfg in xrange(0,len(updated_df_train.index)):
if (updated_df_train.ix[dfg,"selectedLevel"] == selectlvl[n_lvl_val]):
new_temp_updt_df_train = new_temp_updt_df_train.append(updated_df_train.ix[[dfg]],ignore_index=True)
#print new_temp_updt_df_train
"""
Here the Total_Wrongs is the variable which is used to capture the no of wrongs
by taking the count of the total no of questions asked on that particular operator
count_questions_fun is the function used to calculate the counts.
"""
my_list = pd.DataFrame(['questionPair','mathOperator'])
extended_my_list = pd.DataFrame([0])
#print df_train
my_list = df_train[[0,2,3]]
my_list_2 = df_train[[0,2,3,4]]
#print my_list_2
Total_Wrongs = count_questions_fun(my_list_2,extended_my_list,selectlvl,List_Wrongs)
#print Total_Wrongs
#final_list_dataframe = pd.DataFrame([0])
"""
for values in xrange(0,len(list_dataframe)):
if ((list_dataframe.ix[values,'userAnswer'] == 99889988) or (list_dataframe.ix[values,'userAnswer'] == 99779977) or (list_dataframe.ix[values,'userAnswer'] == 123456)):
list_dataframe = list_dataframe.drop(values,0)
list_dataframe = list_dataframe.reset_index(drop=1)
"""
#print list_dataframe
#Total_Wrongs = count_questions_fun(my_list,extended_my_list)
#print Total_Wrongs
my_list = my_list.groupby(['selectedLevel','questionPair','mathOperator']).size().reset_index()
my_list = my_list.rename(columns={0: 'Counts'})
#print my_list
my_new_list = pd.DataFrame()
for o in xrange(0,len(my_list.index)):
if ((my_list.ix[o,'mathOperator'] == mathop)):
my_new_list = (my_new_list.append(my_list.ix[[o]],ignore_index=True)).fillna(0)
my_new_list = my_new_list.sort_values(by=['Counts'],ascending=[False]).reset_index(drop=1)
#print my_new_list
updated_df_train['questionPair_left'], updated_df_train['questionPair_right'] = zip(*updated_df_train['questionPair'].map(lambda x: x.split(',')))
updated_df_train[['questionPair_left', 'questionPair_right']] = updated_df_train[['questionPair_left', 'questionPair_right']].astype(int)
#print df_train
"""
The Left question are taken and all the possible operations like (+,-,*,/) are applied
and saved into the dataframe for kid-operator confusion problem.
"""
updated_df_train['Addition_Ans'] = updated_df_train[['questionPair_left', 'questionPair_right']].sum(axis=1).astype(int)
updated_df_train['Substraction_Ans'] = (updated_df_train['questionPair_left'] - updated_df_train['questionPair_right']).astype(int)
updated_df_train['Multiplication_Ans'] = (updated_df_train['questionPair_left'] * updated_df_train['questionPair_right']).astype(int)
for m in xrange(0,len(updated_df_train.index)):
if ((updated_df_train.ix[m,'questionPair_right'] == 0 and updated_df_train.ix[m,'questionPair_left'] != 0) or (updated_df_train.ix[m,'questionPair_left'] == 0 and updated_df_train.ix[m,'questionPair_right'] == 0)):
updated_df_train.ix[m,'Division_Ans'] = 453453
else:
updated_df_train.ix[m,'Division_Ans'] = (updated_df_train.ix[m,'questionPair_left'] / updated_df_train.ix[m,'questionPair_right']).astype(int)
temp_updated_df_train = updated_df_train
nw_tmp_updt_df = updated_df_train
#print temp_updated_df_train
for values in xrange(0,len(temp_updated_df_train)):
if ((temp_updated_df_train.ix[values,'userAnswer'] == 99889988) or (temp_updated_df_train.ix[values,'userAnswer'] == 99779977) or (temp_updated_df_train.ix[values,'userAnswer'] == 123456)):
temp_updated_df_train = temp_updated_df_train.drop(values,0)
elif ((temp_updated_df_train.ix[values,"userAnswer"] == temp_updated_df_train.ix[values,"Addition_Ans"]) or (temp_updated_df_train.ix[values,"userAnswer"] == temp_updated_df_train.ix[values,"Multiplication_Ans"]) or (temp_updated_df_train.ix[values,"userAnswer"] == temp_updated_df_train.ix[values,"Substraction_Ans"]) or (temp_updated_df_train.ix[values,"userAnswer"] == temp_updated_df_train.ix[values,"Division_Ans"])):
temp_updated_df_train = temp_updated_df_train.drop(values,0)
temp_updated_df_train = temp_updated_df_train.reset_index(drop=1)
#temp_updated_df_train = temp_updated_df_train[[0,3,8,9,4,10,11,12,13]].apply(pd.to_numeric)
temp_updated_df_train = temp_updated_df_train[[0,2,8,9,4,10,11,12,13]].apply(pd.to_numeric)
nw_tmp_updt_df = nw_tmp_updt_df[[0,2,8,9,4,10,11,12,13]].apply(pd.to_numeric)
#temp_updated_df_train = temp_updated_df_train[[0,2,8,9,4,10,11,12,13]]
#print temp_updated_df_train
"""
Here we are checking for the kind of operation and if the requested operation is
substraction then this loop is executed.
"""
if (mathop==2):
lvl_data_df = pd.DataFrame([0])
for lvl_v in range(len(selectlvl)):
for it_1 in xrange(0,len(nw_tmp_updt_df)):
if (nw_tmp_updt_df.ix[it_1,"selectedLevel"] == selectlvl[lvl_v] and selectlvl[lvl_v] <= 4 and mathop==2):
lvl_data_df = lvl_data_df.append(nw_tmp_updt_df.ix[[it_1]],ignore_index=True)
lvl_data_df = lvl_data_df.drop(0,0)
lvl_data_df = lvl_data_df.drop(0,1).reset_index(drop=1)
#print lvl_data_df
plot_x = lvl_data_df[['questionPair_left']]
plot_y = lvl_data_df[['questionPair_right']]
#print plot_x
#print plot_y
plt.plot(plot_x, plot_y, 'ro')
plt.show()
sub_weight_result_df_1_left = pd.DataFrame(['weights(%)'])
sub_weight_result_df_1_right = pd.DataFrame(['weights(%)'])
sub_weight_result_df_2_left = pd.DataFrame(['weights(%)'])
sub_weight_result_df_2_right = pd.DataFrame(['weights(%)'])
sub_weight_result_df_3_left = pd.DataFrame(['weights(%)'])
sub_weight_result_df_3_right = pd.DataFrame(['weights(%)'])
#print my_list_2
my_list_2['questionPair_left'], my_list_2['questionPair_right'] = zip(*my_list_2['questionPair'].map(lambda x: x.split(',')))
my_list_2[['questionPair_left', 'questionPair_right']] = my_list_2[['questionPair_left', 'questionPair_right']].astype(int)
my_list_2["selectedLevel"]=my_list_2["selectedLevel"].apply(pd.to_numeric)
for new_v_1 in xrange(0,len(my_list_2.index)):
if (my_list_2.ix[new_v_1,'selectedLevel'] != selectlvl[0] or my_list_2.ix[new_v_1,'mathOperator'] != mathop):
my_list_2 = my_list_2.drop(new_v_1,0)
my_list_2 = my_list_2.reset_index(drop=1)
#print my_list_2
my_list_2 = my_list_2.groupby(['questionPair_left','questionPair_right']).size().reset_index()
my_list_2 = my_list_2.rename(columns={0: 'Counts'})
#print my_list_2
my_list_2 = my_list_2.sort_values(by=['Counts'],ascending=[False]).reset_index(drop=1)
for count_thresh in xrange(0,len(my_list_2.index)):
if (my_list_2.ix[count_thresh,"Counts"] < 9 ):
my_list_2 = my_list_2.drop(count_thresh,0)
my_list_2 = my_list_2.reset_index(drop = 1)
print my_list_2
zzzz = my_list_2[[0,1,2]].astype(str)
ddnn = pd.crosstab([zzzz.questionPair_left,zzzz.questionPair_right],zzzz.Counts,margins=True)
ddnn_right = pd.crosstab([zzzz.questionPair_right,zzzz.questionPair_left],zzzz.Counts,margins=True)
#p1 = numpy.polyfit(new_temp_my_list.questionPair_left,new_temp_my_list.questionPair_right,1)
#print ddnn
#print p1
ddnn = ddnn.reset_index()
ddnn_right = ddnn_right.reset_index()
#print ddnn
ddnn = ddnn.drop(ddnn.index[len(ddnn)-1])
ddnn_right = ddnn_right.drop(ddnn_right.index[len(ddnn_right)-1])
#print ddnn
#print ddnn_right
#ddnn = ddnn.drop(ddnn.index[len(ddnn)-1])
ddnn = ddnn.apply(pd.to_numeric)
ddnn_right = ddnn_right.apply(pd.to_numeric)
#ddnn = ddnn.drop(0,2)
#ddnn = ddnn
#print ddnn
"""
Based on the level requested for we go into that particular loop and analyse the problems and
later calicluate the weights for left and right question with the total no of wrongs
commited at that particular level
"""
if (selectlvl[0] == 4):
analysis_count_4_1_1,analysis_count_4_1_2,dataframe_4_1,analysis_count_4_2_1,analysis_count_4_2_2,dataframe_4_2 = add_sub_analysis_lvl_4(lvl_data_df)
#print analysis_count_4_1_1
#print analysis_count_4_1_2
#print analysis_count_4_2_1
#print analysis_count_4_2_2
#print dataframe_4_1
#print dataframe_4_2
sending_data_1 = pd.DataFrame()
sending_data_3 = pd.DataFrame()
if (len(analysis_count_4_1_1) != 0 and len(analysis_count_4_1_2) != 0):
sub_weight_result_df_1_left = weights(Total_Wrongs,analysis_count_4_1_1,sub_weight_result_df_1_left)
sub_weight_result_df_1_right = weights(Total_Wrongs,analysis_count_4_1_2,sub_weight_result_df_1_right)
#print sub_weight_result_df_1_left
#print sub_weight_result_df_1_right
for q in xrange(0,len(sub_weight_result_df_1_left)):
sub_weight_result_df_1_left.ix[q,"Right_Question_Choice"] = 1
for q in xrange(0,len(sub_weight_result_df_1_right)):
sub_weight_result_df_1_right.ix[q,"Left_Question_Choice"] = 2
sugg_val_list_left_lvl3 = []
sugg_val_list_right_lvl3 = []
#backup_sugg_val = [[]]
#List_index_val = 0
#print sub_weight_result_df_1_left
#print sub_weight_result_df_1_right
for weig_tab_lvl3 in xrange(0,len(sub_weight_result_df_1_left.index)):
for crs_tab_lvl3 in xrange(0,len(ddnn)):
if (sub_weight_result_df_1_left.ix[weig_tab_lvl3,"Questions"] == ddnn.ix[crs_tab_lvl3,"questionPair_left"] and ddnn.ix[crs_tab_lvl3,"questionPair_right"] <= 9):
sugg_val_list_left_lvl3.append(ddnn.ix[crs_tab_lvl3,"questionPair_right"])
#backup_sugg_val[List_index_val] = sugg_val_list
result_lvl3 = ",".join(map(str,sugg_val_list_left_lvl3))
sub_weight_result_df_1_left.ix[weig_tab_lvl3,"Suggested_Numbers"] = result_lvl3
del sugg_val_list_left_lvl3[:]
#List_index_val
#print result
#print sub_weight_result_df_1_left
for weig_tab_1_lvl3 in xrange(0,len(sub_weight_result_df_1_right.index)):
for crs_tab_1_lvl3 in xrange(0,len(ddnn_right)):
if (sub_weight_result_df_1_right.ix[weig_tab_1_lvl3,"Questions"] == ddnn_right.ix[crs_tab_1_lvl3,"questionPair_right"] and ddnn_right.ix[crs_tab_1_lvl3,"questionPair_left"] > 9):
sugg_val_list_right_lvl3.append(ddnn_right.ix[crs_tab_1_lvl3,"questionPair_left"])
#backup_sugg_val[List_index_val] = sugg_val_list
result_1_lvl3 = ",".join(map(str,sugg_val_list_right_lvl3))
sub_weight_result_df_1_right.ix[weig_tab_1_lvl3,"Suggested_Numbers"] = result_1_lvl3
del sugg_val_list_right_lvl3[:]
#List_index_val
#print sub_weight_result_df_1_right
#print sub_weight_result_df_1_left
sub_weight_result_df_1_left['#Suggested_Numbers'] = sub_weight_result_df_1_left.Suggested_Numbers.map(lambda x: [i.strip() for i in x.split(",")]).apply(len)
sub_weight_result_df_1_right['#Suggested_Numbers'] = sub_weight_result_df_1_right.Suggested_Numbers.map(lambda x: [i.strip() for i in x.split(",")]).apply(len)
for sw_1 in xrange(0,len(sub_weight_result_df_1_left.index)):
if ((sub_weight_result_df_1_left.ix[sw_1,'Suggested_Numbers'] == "" and sub_weight_result_df_1_left.ix[sw_1,'weights(%)'] < 10) or (sub_weight_result_df_1_left.ix[sw_1,'#Suggested_Numbers'] > 1 and sub_weight_result_df_1_left.ix[sw_1,'weights(%)'] < 10)):
sub_weight_result_df_1_left = sub_weight_result_df_1_left.drop(sw_1,0)
#print sub_weight_result_df_1_left
for sw in xrange(0,len(sub_weight_result_df_1_right.index)):
if ((sub_weight_result_df_1_right.ix[sw,'Suggested_Numbers'] == "" and sub_weight_result_df_1_right.ix[sw,'weights(%)'] < 10) or (sub_weight_result_df_1_right.ix[sw,'#Suggested_Numbers'] > 1 and sub_weight_result_df_1_right.ix[sw,'weights(%)'] < 10)):
sub_weight_result_df_1_right = sub_weight_result_df_1_right.drop(sw,0)
#print sub_weight_result_df_1_right
#for amg in xrange(0,len(sub_weight_result_df_1_right.index)):
"""
for i in xrange(0,len(sub_weight_result_df_1_right["Suggested_Numbers"].index)):
sub_weight_result_df_1_right.loc[i, '#Suggested_Numbers'] = len(i.split(","))
sub_weight_result_df_1_right = sub_weight_result_df_1_right.reset_index(drop=1)
print sub_weight_result_df_1_right
"""
sending_data_1= php_data(sub_weight_result_df_1_left,sub_weight_result_df_1_right,selectlvl)
#print sending_data_1
if (len(analysis_count_4_2_1) != 0 and len(analysis_count_4_2_2) != 0):
#print "Helloo iam in the second loop of level 2"
sub_weight_result_df_2_left = weights(Total_Wrongs,analysis_count_4_2_1,sub_weight_result_df_2_left)
sub_weight_result_df_2_right = weights(Total_Wrongs,analysis_count_4_2_2,sub_weight_result_df_2_right)
for q in xrange(0,len(sub_weight_result_df_2_left)):
sub_weight_result_df_2_left.ix[q,"Right_Question_Choice"] = 2
for q in xrange(0,len(sub_weight_result_df_2_right)):
sub_weight_result_df_2_right.ix[q,"Left_Question_Choice"] = 2
sugg_val_list_left_cas2_lvl3 = []
sugg_val_list_right_cas2_lvl3 = []
#print sub_weight_result_df_1_left
#print sub_weight_result_df_1_right
for weig_tab_22_lvl3 in xrange(0,len(sub_weight_result_df_2_left.index)):
for crs_tab_22_lvl3 in xrange(0,len(ddnn)):
if (sub_weight_result_df_2_left.ix[weig_tab_22_lvl3,"Questions"] == ddnn.ix[crs_tab_22_lvl3,"questionPair_left"] and ddnn.ix[crs_tab_22_lvl3,"questionPair_right"] > 9):
sugg_val_list_left_cas2_lvl3.append(ddnn.ix[crs_tab_22_lvl3,"questionPair_right"])
#backup_sugg_val[List_index_val] = sugg_val_list
result_cas2_lvl3= ",".join(map(str,sugg_val_list_left_cas2_lvl3))
sub_weight_result_df_2_left.ix[weig_tab_22_lvl3,"Suggested_Numbers"] = result_cas2_lvl3