Average Daily Usage for wispmon.com Usage Report

Adds an average daily usage calculation to a wispmon.com Usage Report

当前为 2014-07-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Average Daily Usage for wispmon.com Usage Report
  3. // @namespace http://clinton.kopotic.com/
  4. // @version 0.4
  5. // @description Adds an average daily usage calculation to a wispmon.com Usage Report
  6. // @match http://www.wispmon.com/usage/*
  7. // @match http://wispmon.com/usage/*
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @copyright 2014, Clinton Kopotic
  10. // ==/UserScript==
  11.  
  12. /**/
  13.  
  14. var $total_month_usage = $("strong:contains('Total Usage This Month:')");
  15. var $total_month_usage_html = $total_month_usage.html();
  16. var number_of_days = $("strong:contains('Current Month')").nextAll("br").length - 3;
  17. var total_month_usage = parseFloat($total_month_usage_html.substring($total_month_usage_html.indexOf(":") + 1,$total_month_usage_html.indexOf("(")).trim());
  18. console.log(total_month_usage + " / " + number_of_days + " = " + (total_month_usage / number_of_days));
  19. var average_usage = total_month_usage / number_of_days;
  20. var average_usage_html = "<strong>Average Daily Usage: " + average_usage.toFixed(4) + "</strong><br>";
  21. $total_month_usage.next().after(average_usage_html);
  22.  
  23. /**/
  24.  
  25. /* A better algorithm would be:
  26. * 1) read through each of the days in current month parsing:
  27. * a) date
  28. * b) upload total
  29. * c) download total
  30. */
  31. function DateLine(startDate, endDate, uploadAmount, uploadUnits, downloadAmount, downloadUnits) {
  32. this.startDate = startDate;
  33. this.endDate = endDate;
  34. this.uploadAmount = uploadAmount;
  35. this.uploadUnits = uploadUnits;
  36. this.downloadAmount = downloadAmount;
  37. this.downloadUnits = downloadUnits;
  38. this.toString = function () { return startDate + " - " + endDate };
  39. }
  40.  
  41. var $current_month = $("strong:contains('Current Month')");
  42. var $days_list = $current_month.nextUntil('strong');
  43. var days_list_length = $days_list.length - 1;
  44. var days_list_array = [];
  45. var total_upload = 0.0;
  46. var total_download = 0.0;
  47.  
  48. for (var i = 0; i < days_list_length; ++i) {
  49. var date_line_split_array = $days_list.eq(i).prop("nextSibling").data.split(" ");
  50. days_list_array[i] = new DateLine(
  51. date_line_split_array[0],
  52. date_line_split_array[2],
  53. parseFloat(date_line_split_array[4]),
  54. date_line_split_array[5],
  55. parseFloat(date_line_split_array[8]),
  56. date_line_split_array[9]
  57. );
  58. total_upload += days_list_array[i].uploadAmount;
  59. total_download += days_list_array[i].downloadAmount;
  60. }
  61. var now_date = new Date();
  62. var days_in_month = new Date(now_date.getFullYear(), now_date.getMonth(), 0).getDate() + 1;
  63. var day_of_month = (now_date.getHours() >= 3) ? now_date.getDate() : now_date.getDate() - 1;
  64. console.log(day_of_month);
  65. console.log(days_in_month);
  66. $total_month_usage.next().after("<strong>Average Daily Upload Usage: " + (total_upload / days_list_length).toFixed(4) + "</strong><br>");
  67. $total_month_usage.next().after("<strong>Average Daily Download Usage: " + (total_download / days_list_length).toFixed(4) + "</strong><br>");
  68. $total_month_usage.next().after("<strong>Total Upload Usage: " + (total_upload).toFixed(4) + " (" + ((total_upload / 7.32) * 100.0).toFixed(2) + "%)" + "</strong><br>");
  69. $total_month_usage.next().after("<strong>Total Download Usage: " + (total_download).toFixed(4) + " (" + ((total_download / 29.3) * 100.0).toFixed(2) + "%)" + "</strong><br>");
  70. $total_month_usage.next().after("<strong>Percent Through Month: " + ((day_of_month / days_in_month) * 100.0).toFixed(2) + "%" + "</strong><br>");
  71. /*
  72. * 2) Calculate the upload and download totals from 1)
  73. * 3) Determine the end date (not necessarily from 1))
  74. * 4) Provide daily averages for upload and download
  75. * 5) Provide percentage limit total of upload and download via cookies and forms
  76. */