/Source/ItJobStudy/www/htdocs/m/IndStats.php

https://github.com/mccollek/IT-oLogy--IT-Jobs-Report-Application · PHP · 150 lines · 103 code · 29 blank · 18 comment · 1 complexity · 9ed513f7849898742de486d7e3e2cb53 MD5 · raw file

  1. <?php
  2. include_once('/srv/www/htdocs/m/table.php');
  3. class IndStats extends Table {
  4. protected function bind_StateITJobs(&$stmt, &$row) {
  5. mysqli_stmt_bind_result($stmt, $row->stateName, $row->jobs);
  6. $this->throwExceptionOnError();
  7. }
  8. public function getStateITJobs($year) {
  9. $query = "SELECT stateName, sum(jobs) AS jobs
  10. FROM indStateITStats
  11. WHERE year='$year'
  12. AND stateName NOT IN ('District of Columbia', 'Guam', 'Puerto Rico',
  13. 'Virgin Islands')
  14. GROUP BY stateName";
  15. return $this->get_rows($query, 'bind_StateITJobs');
  16. }
  17. /*
  18. * Provide data representing the percent of a state's domestic production is
  19. * produced by IT industries.
  20. */
  21. // Utility function to bind database results in $stmt to data structure, $row.
  22. protected function bind_GSProws(&$stmt, &$row) {
  23. mysqli_stmt_bind_result($stmt, $row->stateAbr, $row->stateName, $row->gsp);
  24. $this->throwExceptionOnError();
  25. }
  26. // Input: year
  27. // Output: stateAbr, stateName, percentITGSP/percentAllGSP
  28. // [(State Wide IT Jobs)*(State Wide IT Jobs Avg Salary)] /
  29. // [(State Wide All Jobs)*(State Wide All Jobs Avg Salary)] * 100
  30. public function getPercentITofGSP($year) {
  31. $query = "SELECT stateAbr, stateName, SUM(jobs)*AVG(salary) as gsp
  32. FROM %s WHERE year = '$year' %s GROUP BY stateAbr ORDER BY stateAbr";
  33. // get
  34. $totalRows = $this->get_rows(sprintf($query, 'indStateStats', 'AND naics=\'10\''),
  35. 'bind_GSProws');
  36. $itRows = $this->get_rows(sprintf($query, 'indStateITStats', ''),
  37. 'bind_GSProws');
  38. $row = new stdClass();
  39. for($i=0; $i<count($itRows); $i++) {
  40. $row->stateAbr = $itRows[$i]->stateAbr;
  41. $row->stateName = $itRows[$i]->stateName;
  42. $row->gsp = 100*number_format($itRows[$i]->gsp / $totalRows[$i]->gsp, 4);
  43. $rows[] = $row;
  44. $row = new stdClass();
  45. }
  46. return $rows;
  47. }
  48. //IT jobs & salary by state:
  49. // 2000, SUM(jobs), SUM(salary)
  50. public function bind_ITStatsByYear(&$stmt, &$row) {
  51. mysqli_stmt_bind_result($stmt, $row->year, $row->jobs, $row->orgs, $row->salary);
  52. $this->throwExceptionOnError();
  53. }
  54. public function getIndITStatsByState($state) {
  55. $query = "SELECT year, SUM(jobs) AS jobs, SUM(orgs) AS orgs, AVG(salary) AS salary
  56. FROM indStateITStats WHERE stateAbr='$state' GROUP BY year ASC";
  57. return $this->get_rows($query, 'bind_ITStatsByYear');
  58. }
  59. //IT jobs & salary by state:
  60. // 2000, SUM(jobs), SUM(salary)
  61. public function getIndITStatsByStateByNaics($state, $naics) {
  62. $query = "SELECT year, SUM(jobs) AS jobs, SUM(orgs) AS orgs, AVG(salary) AS salary
  63. FROM indStateITStats WHERE stateAbr='$state' AND naics = '$naics'
  64. GROUP BY year ASC";
  65. return $this->get_rows($query, 'bind_ITStatsByYear');
  66. }
  67. //by year => of sum of all data for a given state
  68. protected function bind_itStatsByNaics(&$stmt, &$row) {
  69. mysqli_stmt_bind_result($stmt,
  70. $row->naics, $row->indName, $row->indDescrip,
  71. $row->jobs, $row->orgs, $row->salary);
  72. $this->throwExceptionOnError();
  73. }
  74. public function getIndITStatsByYearByState($year, $state) {
  75. $query = "SELECT naics, indName, indDescrip,
  76. SUM(jobs) AS jobs, SUM(orgs) as orgs, AVG(salary) AS salary
  77. FROM indStateITStats WHERE year = '$year' AND stateAbr = '$state'
  78. GROUP BY naics";
  79. return $this->get_rows($query, 'bind_itStatsByNaics');
  80. }
  81. public function getIndNationalITStatsByYear($year) {
  82. //by year => of sum of all data for all states
  83. $query = "SELECT naics, indName, indDescrip,
  84. SUM(jobs) AS jobs, SUM(orgs) as orgs, AVG(salary) AS salary
  85. FROM indStateITStats WHERE year = '$year' GROUP BY naics";
  86. return $this->get_rows($query, 'bind_itStatsByNaics');
  87. }
  88. protected function bind_itIndustryDetails(&$stmt, &$row) {
  89. mysqli_stmt_bind_result($stmt, $row->naics, $row->name, $row->descrip,
  90. $row->source);
  91. $this->throwExceptionOnError();
  92. }
  93. public function getITIndustryDetails() {
  94. $query = 'SELECT naics, name, descrip, source FROM industriesIT ORDER BY name';
  95. return $this->get_rows($query, 'bind_itIndustryDetails');
  96. }
  97. public function getITIndustryDetailsByState($state) {
  98. $query = "SELECT naics, indName, indDescrip, indSource
  99. FROM indStateITStats WHERE stateAbr = '$state'
  100. GROUP BY naics ORDER BY indName";
  101. return $this->get_rows($query, 'bind_itIndustryDetails');
  102. }
  103. public function getNonITIndustryDetailsByState($state) {
  104. $query = "SELECT naics, indName, indDescrip, indSource
  105. FROM indStateNonITStats WHERE stateAbr = '$state'
  106. GROUP BY naics ORDER by indName";
  107. return $this->get_rows($query, 'bind_ITIndustryDetails');
  108. }
  109. //IT naics, job names, jobs, and salary by state:
  110. // 2010, naics, job name, jobs, salary
  111. protected function bind_year_extrema(&$stmt, &$row) {
  112. mysqli_stmt_bind_result($stmt, $row->min, $row->max);
  113. $this->throwExceptionOnError();
  114. }
  115. public function get_year_extrema() {
  116. $query = 'SELECT min(indStateITStats.year), max(indStateITStats.year)
  117. FROM indStateITStats';
  118. return $this->get_rows($query, 'bind_yearExtrema');
  119. }
  120. }
  121. ?>