StatisVC.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // StatisVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/20.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "StatisVC.h"
  9. #import "PieView.h"
  10. #import "Grade.h"
  11. @interface StatisVC ()<PieViewDataSource>
  12. {
  13. NSInteger cntUndo;
  14. NSInteger cntFault;
  15. NSInteger cntCorrect;
  16. NSInteger cntAll;
  17. PieView* pieV;
  18. UILabel* lbl00,*lbl01,*lbl10,*lbl11,*lbl20,*lbl21;
  19. NSArray* colors;
  20. }
  21. @end
  22. @implementation StatisVC
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. [self myInit];
  27. [self getStatis];
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. // Dispose of any resources that can be recreated.
  32. }
  33. #pragma mark -
  34. -(void)myInit
  35. {
  36. [self configNavigationBar];
  37. [self setTitle:@"练习统计"];
  38. [self.view setBackgroundColor:backGroundColor];
  39. colors = @[contentTextColor,[UIColor orangeColor],defGreen];
  40. UIView *vi;
  41. CGFloat bd = 0;
  42. CGFloat pieH = 320* .5;
  43. vi = [[UIView alloc] initWithFrame:SGRectMake(0, 0, 320, pieH + bd*2)];
  44. [vi setBackgroundColor:backGroundColor];
  45. [self.view addSubview:vi];
  46. pieV = [[PieView alloc] init];
  47. [pieV setBounds:SGRectMake(0, 0, pieH, pieH)];
  48. [pieV setCenter:vi.center];
  49. [pieV setDatasource:self];
  50. [self.view addSubview:pieV];
  51. UILabel* label;
  52. CGFloat currentTop;
  53. CGFloat lblH;
  54. currentTop = pieH + bd*2;
  55. bd = 5;
  56. lblH = 25;
  57. label = [[UILabel alloc] initWithFrame:SGRectMake(bd, currentTop, 320 - bd*2, lblH)];
  58. [label setText:@"练习统计"];
  59. [label setTextAlignment:NSTextAlignmentCenter];
  60. [self.view addSubview:label];
  61. [label setBackgroundColor:[UIColor whiteColor]];
  62. currentTop += lblH ;
  63. vi = [[UIView alloc] initWithFrame:SGRectMake(bd, currentTop+1, 320-bd*2, lblH*3)];
  64. [vi setBackgroundColor:[UIColor whiteColor]];
  65. [self.view addSubview:vi];
  66. CGFloat lblw;
  67. lblw = (320-bd*4)/3;
  68. NSArray* titles = @[@"未做题",@"1126",@"91%",
  69. @"答错题",@"64",@"5%",
  70. @"答对题",@"39",@"3%"];
  71. for (int i = 0; i< 9; i++) {
  72. label = [[UILabel alloc] initWithFrame:SGRectMake(bd + lblw*(i%3), lblH*(i/3), lblw, lblH)];
  73. [label setText:titles[i]];
  74. [vi addSubview:label];
  75. int x = i%3;
  76. int y = i/3;
  77. [label setTextColor:colors[y]];
  78. if ( 1 == x )
  79. {
  80. [label setTextAlignment:NSTextAlignmentCenter];
  81. }
  82. if ( 2 == x) {
  83. [label setTextAlignment:NSTextAlignmentRight];
  84. }
  85. switch (i) {
  86. case 1:
  87. lbl00 = label;
  88. break;
  89. case 2:
  90. lbl01 = label;
  91. break;
  92. case 4:
  93. lbl10 = label;
  94. break;
  95. case 5:
  96. lbl11 = label;
  97. break;
  98. case 7:
  99. lbl20 = label;
  100. break;
  101. case 8:
  102. lbl21 = label;
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. }
  109. -(void)getStatis
  110. {
  111. // sqlite3 *database;
  112. // sqlite3_open([dataBasePath2 UTF8String], &database);
  113. //
  114. // sqlite3_stmt *statement;
  115. //获取数据库的表的名字
  116. // const char *getTableInfo = "select * from sqlite_master where type='table' order by name";
  117. // sqlite3_prepare_v2(database, getTableInfo, -1, &statement, nil);
  118. // while (sqlite3_step(statement) == SQLITE_ROW) {
  119. // char *nameData = (char *)sqlite3_column_text(statement, 1);
  120. // NSString *tableName = [[NSString alloc] initWithUTF8String:nameData];
  121. // NSLog(@"name:%@",tableName);
  122. // }
  123. // NSString *columnName = @"";
  124. // //获取某表中字段的名字
  125. // const char *getColumn = "PRAGMA table_info(question)";
  126. // sqlite3_prepare_v2(database, getColumn, -1, &statement, nil);
  127. // while (sqlite3_step(statement) == SQLITE_ROW) {
  128. // char *nameData = (char *)sqlite3_column_text(statement, 1);
  129. // columnName = [[NSString alloc] initWithUTF8String:nameData];
  130. // NSLog(@"columnName:%@",columnName);
  131. // }
  132. //
  133. // sqlite3_finalize(statement);
  134. NSString *sql1 = [NSString stringWithFormat:@"subject = %@",myDelegate.subject];
  135. if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
  136. {
  137. sql1 = @"nil";
  138. }
  139. cntFault = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count);
  140. cntAll = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential].count : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper countForQuery:sql1] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential].count);
  141. int done = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (int)[DB_Que_Helper queryMarkQuestionWithMarkType:@"4"] : ([defUser.car_type isEqualToString:@"2"]? (int)[DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"4"] : (int)[DB_Que_Helper queryMarkQuestionWithMarkType:@"4"]);
  142. cntUndo = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo].count : ([defUser.car_type isEqualToString:@"2"]? cntAll - done : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo].count);
  143. cntCorrect = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (cntAll - cntFault - cntUndo) : ([defUser.car_type isEqualToString:@"2"]? done - cntFault : cntAll - cntFault - cntUndo);
  144. //NSLog(@"cntFault----->%d,cntCorrect----->%d,cntUndo------>%d,cntAll------>%d",(int)cntFault,(int)cntCorrect,(int)cntUndo,(int)cntAll);
  145. [pieV reloadData];
  146. [lbl00 setText:[NSString stringWithFormat:@"%d",(int)cntUndo]];
  147. [lbl01 setText:[NSString stringWithFormat:@"%.2f%%",!((cntUndo*100.0/cntAll) < 0)? cntUndo*100.0/cntAll : 0.00]];
  148. [lbl10 setText:[NSString stringWithFormat:@"%d",(int)cntFault]];
  149. [lbl11 setText:[NSString stringWithFormat:@"%.2f%%",cntFault*100.0/cntAll]];
  150. [lbl20 setText:[NSString stringWithFormat:@"%d",(int)cntCorrect]];
  151. [lbl21 setText:[NSString stringWithFormat:@"%.2f%%",cntCorrect*100.0/cntAll]];
  152. }
  153. #pragma mark -
  154. - (int)numberOfSlicesInPieChartView:(PieView *)pieChartView
  155. {
  156. return 3;
  157. }
  158. /**
  159. 返回某个index的饼片的比例。0-100
  160. */
  161. - (double)pieChartView:(PieView *)pieChartView valueForSliceAtIndex:(NSUInteger)index
  162. {
  163. NSInteger cnt;
  164. switch (index) {
  165. case 0:
  166. cnt = cntUndo ;
  167. break;
  168. case 1:
  169. cnt = cntFault;
  170. break;
  171. case 2:
  172. cnt = cntCorrect;
  173. break;
  174. default:
  175. cnt = 1;
  176. break;
  177. }
  178. return cnt*100.0 / cntAll;
  179. }
  180. /**返回某个index饼片的颜色
  181. */
  182. - (UIColor *)pieChartView:(PieView *)pieChartView colorForSliceAtIndex:(NSUInteger)index
  183. {
  184. return colors[index];
  185. }
  186. @end