ovid.pl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. $infile = $ARGV[0];
  2. open(INFILE, $infile) || die("Could not open file $infile\nError: $!");
  3. # Perl trim function to remove whitespace from the start and end of the string
  4. sub trim($)
  5. {
  6. my $string = shift;
  7. $string =~ s/^\s+//;
  8. $string =~ s/\s+$//;
  9. return $string;
  10. }
  11. # Taken from Nokia Developer device specifications:
  12. # https://www.developer.nokia.com/Devices/Device_specifications/
  13. # There's no way of knowing if a Symbian^3 device has been updated
  14. # to Anna or Belle or Klickerklok so the best we can do is to
  15. # categorise according to OS at launch.
  16. my @SymbianBelle = (
  17. "Nokia 500 Belle",
  18. "Nokia 600",
  19. "Nokia 603",
  20. "Nokia 700",
  21. "Nokia 701",
  22. "Nokia 808 Pureview",
  23. "Nokia C6-01 Belle",
  24. "Nokia C7-00 Belle",
  25. "Nokia E6-00 Belle",
  26. "Nokia E7-00 Belle",
  27. "Nokia N8-00 Belle",
  28. "Nokia X7-00 Belle"
  29. );
  30. my $SymbianBellefound = 0;
  31. my $SymbianBellepercent = 0;
  32. my @SymbianAnna = ("Nokia 500",
  33. "Nokia Oro",
  34. "Nokia E6-00",
  35. "Nokia X7-00");
  36. my $SymbianAnnafound = 0;
  37. my $SymbianAnnapercent = 0;
  38. my @Symbian3 = ("Nokia C6-01",
  39. "Nokia C7 Astound",
  40. "Nokia C7-00",
  41. "Nokia E7-00",
  42. "Nokia N8-00",
  43. "Nokia Oro Belle",
  44. "Vertu Constellation T",
  45. "Symbian3");
  46. my $Symbian3found = 0;
  47. my $Symbian3percent = 0;
  48. my @Symbian1 = ("Nokia 5228",
  49. "Nokia 5230",
  50. "Nokia 5230 Nuron",
  51. "Nokia 5233",
  52. "Nokia 5235",
  53. "Nokia 5235 Ovi Music Unlimited",
  54. "Nokia 5250",
  55. "Nokia 5530 XpressMusic",
  56. "Nokia 5800 XpressMusic",
  57. "Nokia C5-03",
  58. "Nokia C5-04",
  59. "Nokia C6-00",
  60. "Nokia N97",
  61. "Nokia N97 mini",
  62. "Nokia X6",
  63. "Nokia X6-00");
  64. my $Symbian1found = 0;
  65. my $Symbian1percent = 0;
  66. my @S603rdFP2 = ("Nokia 5320 XpressMusic",
  67. "Nokia 5630 XpressMusic",
  68. "Nokia 5730 XpressMusic",
  69. "Nokia 6210 Navigator",
  70. "Nokia 6220 classic",
  71. "Nokia 6650 fold",
  72. "Nokia 6700 slide",
  73. "Nokia 6710 Navigator",
  74. "Nokia 6720 classic",
  75. "Nokia 6730 classic",
  76. "Nokia 6760 slide",
  77. "Nokia 6788",
  78. "Nokia 6788i",
  79. "Nokia 6790 Surge",
  80. "Nokia 6790 slide",
  81. "Nokia C5-00",
  82. "Nokia C5-01",
  83. "Nokia E5-00",
  84. "Nokia E52",
  85. "Nokia E55",
  86. "Nokia E71x",
  87. "Nokia E72",
  88. "Nokia E73",
  89. "Nokia E73 Mode",
  90. "Nokia E75",
  91. "Nokia N78",
  92. "Nokia N79",
  93. "Nokia N85",
  94. "Nokia N86 8MP",
  95. "Nokia N96",
  96. "Nokia N96-3",
  97. "Nokia N96-3 NAM",
  98. "Nokia X5-00",
  99. "Vertu Constellation Quest",
  100. "Nokia X5-01");
  101. my $S603rdFP2found = 0;
  102. my $S603rdFP2percent = 0;
  103. my @S603rdFP1 = ("Nokia 5700 XpressMusic",
  104. "Nokia 6110 Navigator",
  105. "Nokia 6120 classic",
  106. "Nokia 6121 classic",
  107. "Nokia 6124 classic",
  108. "Nokia 6290",
  109. "Nokia E51",
  110. "Nokia E63",
  111. "Nokia E66",
  112. "Nokia E71",
  113. "Nokia E90 Communicator",
  114. "Nokia N76",
  115. "Nokia N81",
  116. "Nokia N81 8GB",
  117. "Nokia N82",
  118. "Nokia N95",
  119. "Nokia N95 8GB",
  120. "Nokia N95-3 NAM");
  121. my $S603rdFP1found = 0;
  122. my $S603rdFP1percent = 0;
  123. my @S603rdIR = ("Nokia 3250",
  124. "Nokia 5500 Sport",
  125. "Nokia E50",
  126. "Nokia E60",
  127. "Nokia E61",
  128. "Nokia E61i",
  129. "Nokia E62",
  130. "Nokia E65",
  131. "Nokia E70",
  132. "Nokia N71",
  133. "Nokia N73",
  134. "Nokia N75",
  135. "Nokia N77",
  136. "Nokia N80",
  137. "Nokia N80 Internet Edition",
  138. "Nokia N91",
  139. "Nokia N91 8GB",
  140. "Nokia N92",
  141. "Nokia N93",
  142. "Nokia N93i");
  143. my $S603rdIRfound = 0;
  144. my $S603rdIRpercent = 0;
  145. my $unknownfound = 0;
  146. my $unknownpercent = 0;
  147. while (<INFILE>) {
  148. chomp;
  149. my ($rank, $phone, $percent) = split('\t');
  150. $phone = trim($phone);
  151. $percent =~ s/[\s]//g;
  152. #print "$rank--$phone--$percent--\n";
  153. $totalfound++;
  154. $totalpercent += $percent;
  155. if (grep /^$phone$/i, @SymbianBelle) {
  156. print "$rank\t$percent\tSymbian Belle\t$phone\n";
  157. $SymbianBellefound++;
  158. $SymbianBellepercent += $percent;
  159. }
  160. elsif (grep /^$phone$/i, @SymbianAnna) {
  161. print "$rank\t$percent\tSymbian Anna\t$phone\n";
  162. $SymbianAnnafound++;
  163. $SymbianAnnapercent += $percent;
  164. }
  165. elsif (grep /^$phone$/i, @Symbian3) {
  166. print "$rank\t$percent\tSymbian^3\t$phone\n";
  167. $Symbian3found++;
  168. $Symbian3percent += $percent;
  169. }
  170. elsif (grep /^$phone$/i, @Symbian1) {
  171. print "$rank\t$percent\tSymbian^1\t$phone\n";
  172. $Symbian1found++;
  173. $Symbian1percent += $percent;
  174. }
  175. elsif (grep /^$phone$/i, @S603rdFP2) {
  176. print "$rank\t$percent\tS60 3.2 \t$phone\n";
  177. $S603rdFP2found++;
  178. $S603rdFP2percent += $percent;
  179. }
  180. elsif (grep /^$phone$/i, @S603rdFP1) {
  181. print "$rank\t$percent\tS60 3.1 \t$phone\n";
  182. $S603rdFP1found++;
  183. $S603rdFP1percent += $percent;
  184. }
  185. elsif (grep /^$phone$/i, @S603rdIR) {
  186. print "$rank\t$percent\tS60 3.0 \t$phone\n";
  187. $S603rdIRfound++;
  188. $S603rdIRpercent += $percent;
  189. }
  190. else {
  191. print "$rank\t$percent\tUNKNOWN \t$phone\n";
  192. $unknownfound++;
  193. $unknownpercent += $percent;
  194. }
  195. }
  196. close(INFILE);
  197. my $totalS603rdfound = $S603rdFP2found + $S603rdFP1found + $S603rdIRfound;
  198. my $totalS603rdpercent = $S603rdFP2percent + $S603rdFP1percent + $S603rdIRpercent;
  199. print "=============================\n";
  200. print "$SymbianBellefound Symbian Belle models:\t$SymbianBellepercent%\n";
  201. print "$SymbianAnnafound Symbian Anna models:\t$SymbianAnnapercent%\n";
  202. print "$Symbian3found Symbian^3 models:\t$Symbian3percent%\n";
  203. print "$Symbian1found Symbian^1 models:\t$Symbian1percent%\n";
  204. print "$totalS603rdfound S60 3rd edition:\t$totalS603rdpercent%\n";
  205. print "-----------------------------\n";
  206. print "$S603rdFP2found S60 3.2 models:\t$S603rdFP2percent%\n";
  207. print "$S603rdFP1found S60 3.1 models:\t$S603rdFP1percent%\n";
  208. print "$S603rdIRfound S60 3.0 models:\t$S603rdIRpercent%\n";
  209. print "-----------------------------\n";
  210. print "$unknownfound unknown models:\t$unknownpercent%\n";
  211. print "=============================\n";
  212. print "$totalfound total models:\t$totalpercent%\n";
  213. print "=============================\n";
  214. # Disregard the unknown so total = 100%
  215. my $fixfactor = 100 / (100 - $unknownpercent);
  216. $SymbianBellepercent *= $fixfactor;
  217. $SymbianAnnapercent *= $fixfactor;
  218. $Symbian3percent *= $fixfactor;
  219. $Symbian1percent *= $fixfactor;
  220. $totalS603rdpercent *= $fixfactor;
  221. $S603rdFP2percent *= $fixfactor;
  222. $S603rdFP1percent *= $fixfactor;
  223. $S603rdIRpercent *= $fixfactor;
  224. print "\nIgnoring the unknown:\n";
  225. print "=============================\n";
  226. printf "$SymbianBellefound Symbian Belle models:\t%.1f%\n", $SymbianBellepercent;
  227. printf "$SymbianAnnafound Symbian Anna models:\t%.1f%\n", $SymbianAnnapercent;
  228. printf "$Symbian3found Symbian^3 models:\t%.1f%\n", $Symbian3percent;
  229. printf "$Symbian1found Symbian^1 models:\t%.1f%\n", $Symbian1percent;
  230. printf "$totalS603rdfound S60 3rd ed. models:\t%.f%\n", $totalS603rdpercent;
  231. print "-----------------------------\n";
  232. printf "$S603rdFP2found S60 3.2 models:\t%.1f%\n", $S603rdFP2percent;
  233. printf "$S603rdFP1found S60 3.1 models:\t%.1f%\n", $S603rdFP1percent;
  234. printf "$S603rdIRfound S60 3.0 models:\t%.1f%\n", $S603rdIRpercent;
  235. print "=============================\n";
  236. $totalfound -= $unknownfound;
  237. $totalpercent = $SymbianBellepercent
  238. + $SymbianAnnapercent
  239. + $Symbian3percent
  240. + $Symbian1percent
  241. + $S603rdFP2percent
  242. + $S603rdFP1percent
  243. + $S603rdIRpercent;
  244. printf "%d total models:\t%.1f%\n", $totalfound, $totalpercent;
  245. print "=============================\n";
  246. # Write the data to a file so it can be drawn as a stacked line graph
  247. if (-e "ovid.data") {
  248. # '>>', the file is opened for appending, being created if necessary
  249. open(OUTFILE, ">>ovid.data") || die "Can't open the output file\nError: $!";
  250. } else {
  251. # '>', the file is truncated and opened for output, being created if necessary
  252. open(OUTFILE, ">ovid.data") || die "Can't open the output file\nError: $!";
  253. print OUTFILE "Month\tSymbian_Belle\tSymbian_Anna\tSymbian^3\tSymbian^1\tS60_3.2\tS60_3.1\tS60_3.0\n";
  254. }
  255. my $stackedSymbianAnnapercent = $SymbianBellepercent + $SymbianAnnapercent;
  256. my $stackedSymbian3percent = $stackedSymbianAnnapercent + $Symbian3percent;
  257. my $stackedSymbian1percent = $stackedSymbian3percent + $Symbian1percent;
  258. my $stackedS603rdFP2percent = $stackedSymbian1percent + $S603rdFP2percent;
  259. my $stackedS603rdFP1percent = $stackedS603rdFP2percent + $S603rdFP1percent;
  260. # my $stackedS603rdIRpercent = $stackedS603rdFP1percent + $S603rdIRpercent;
  261. # Smooth off the rounding errors from adding rounded percentages:
  262. my $stackedS603rdIRpercent = 100;
  263. print OUTFILE "$infile\t$SymbianBellepercent%\t$stackedSymbianAnnapercent%\t$stackedSymbian3percent%\t$stackedSymbian1percent%\t$stackedS603rdFP2percent%\t$stackedS603rdFP1percent%\t$stackedS603rdIRpercent%\n";
  264. close(OUTFILE);