| <?php | |
| /******************************************************************************* | |
| * Copyright (c) 2011 Eclipse Foundation and others. | |
| * All rights reserved. This program and the accompanying materials | |
| * are made available under the terms of the Eclipse Public License v1.0 | |
| * which accompanies this distribution, and is available at | |
| * http://www.eclipse.org/legal/epl-v10.html | |
| * | |
| * Contributors: | |
| * Wayne Beaton (Eclipse Foundation)- initial API and implementation | |
| *******************************************************************************/ | |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); | |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/projects/classes/debug.php"); | |
| $App = new App(); | |
| header("Content-type: text/plain"); | |
| $year = date('Y', strtotime('now')); | |
| $month = date('m', strtotime('now')); | |
| $base = strtotime("-1 month", strtotime("$year-$month-01")); | |
| // for ($i = 18; $i >= 0; $i--) { | |
| // $start = strtotime("-$i month", $base); | |
| // $end = strtotime("+1 month", $start); | |
| // $period = date('M-Y', $start); | |
| // $yearmonth = date('Ym', $start); | |
| // $start = date('Y-m-d', $start); | |
| // $end = date('Y-m-d', $end); | |
| // $projectCount = findProjectCount($start, $end); | |
| // $proposalCount = findProposalCount($start, $end); | |
| // $committerCount = findCommitterCount($start, $end); | |
| // $activeCommitterCount = findActiveCommitterCount($yearmonth); | |
| // $companyCount = findCompanyCount($start, $end); | |
| // echo "$period, $projectCount, $proposalCount, $committerCount, $activeCommitterCount, $companyCount\n"; | |
| // } | |
| echo getProjectChartUrl(); | |
| function getProjectChartUrl($start=null, $count=18) { | |
| if (!$start) $start = strtotime('-1 month', strtotime(date('Y-m-01'))); | |
| $labels = array(); | |
| $projects = array(); | |
| $active = array(); | |
| for($index = $count-1;$index >= 0;$index--) { | |
| $period = strtotime("-$index month", $start); | |
| $labels[] = count($labels) % 3 == 2 ? date('M-Y', $period) : ''; | |
| $projects[] = findProjectCount($period); | |
| $active[] = findActiveProjectCount($period); | |
| } | |
| $max = max(max($projects), max($active)) + 10; | |
| $min = min(min($projects), min($active)) - 10; | |
| $labels = join('|', $labels); | |
| $projects = join(',', $projects); | |
| $active = join(',', $active); | |
| $url = "http://chart.apis.google.com/chart | |
| ?chxl=0:|$labels | |
| &chxr=0,$min,$max|1,$min,$max | |
| &chxs=0,676767,11.5,0.5,lt,676767|1,676767,12.5,0,lt,676767 | |
| &chxt=x,y | |
| &chs=460x220 | |
| &cht=lc | |
| &chco=3072F3,FF9900 | |
| &chds=$min,$max,$min,$max | |
| &chd=t:$projects|$active | |
| &chdl=Total+Projects|Active+Projects | |
| &chdlp=b | |
| &chls=2|1 | |
| &chma=5,0,5,15|5,5 | |
| &chtt=Projects"; | |
| return preg_replace('/\s/','',$url); | |
| } | |
| /** | |
| * This function returns the count of active projects during the provided | |
| * range of dates. A project is considered active if the IsActive flag is | |
| * set and it has at least one person active in any role during the range | |
| * of dates. | |
| * | |
| * @param int $period | |
| */ | |
| function findProjectCount($period) { | |
| global $App; | |
| $start = date('Y-m-01', $period); | |
| $end = date('Y-m-d', strtotime('+1 month', strtotime($start))); | |
| $sql = "SELECT count(distinct Projects.ProjectID) | |
| from Projects | |
| join PeopleProjects on (Projects.ProjectID = PeopleProjects.ProjectID) | |
| where | |
| Projects.IsActive | |
| and ActiveDate < date '$end' | |
| and (InactiveDate is null or InactiveDate > date '$start')"; | |
| echo "$sql\n"; | |
| $result = $App->foundation_sql($sql); | |
| if ($row = mysql_fetch_array($result)) return $row[0]; | |
| return null; | |
| } | |
| function findActiveProjectCount($period) { | |
| return 25; | |
| } | |
| /** | |
| * This function returns the count of committers who were active between the | |
| * range of provided dates. A committer is considered active if they have | |
| * a UNIX Account (i.e. they have been provisioned as a committer), were | |
| * made active either before or during the provided range, and have either | |
| * not been made inactive, or their inactive date is either after or during | |
| * the provided range. | |
| * | |
| * @param date $start | |
| * @param date $end | |
| */ | |
| function findCommitterCount($start, $end) { | |
| global $App; | |
| $sql = "SELECT | |
| COUNT(DISTINCT PeopleProjects.PersonID) | |
| from PeopleProjects | |
| join People on (PeopleProjects.PersonID = People.PersonID) | |
| WHERE | |
| Relation = 'CM' and IsUnixAcctCreated | |
| and ActiveDate < date '$end' | |
| and (InactiveDate is null or InactiveDate > date '$start')"; | |
| $result = $App->foundation_sql($sql); | |
| if ($row = mysql_fetch_array($result)) return $row[0]; | |
| return null; | |
| } | |
| /** | |
| * This function returns the count of companies who had at least one | |
| * committers who were active between the range of provided dates. A | |
| * committer is considered active if they have | |
| * a UNIX Account (i.e. they have been provisioned as a committer), were | |
| * made active either before or during the provided range, and have either | |
| * not been made inactive, or their inactive date is either after or during | |
| * the provided range. | |
| * | |
| * @param date $start | |
| * @param date $end | |
| */ | |
| function findCompanyCount($start, $end) { | |
| global $App; | |
| $sql = "SELECT | |
| count(distinct o.OrganizationID) | |
| from People as p | |
| join OrganizationContacts as o on (p.PersonID = o.PersonId) | |
| join PeopleProjects as pr on (p.PersonId = pr.PersonId) | |
| where | |
| o.relation = 'EMPLY' and IsUnixAcctCreated | |
| and pr.ActiveDate < date '$end' | |
| and (pr.InActiveDate is null or pr.InActiveDate >= date '$start')"; | |
| $result = $App->foundation_sql($sql); | |
| if ($row = mysql_fetch_array($result)) return $row[0]; | |
| return null; | |
| } | |
| /** | |
| * Return the number of active committers during the specified period. | |
| * The period is specified in yearmonth form (e.g. 201108). | |
| * | |
| * @param string $period | |
| */ | |
| function findActiveCommitterCount($period) { | |
| global $_activeCommitters; | |
| if (!$_activeCommitters) { | |
| $raw = file_get_contents('http://dash.eclipse.org/dash/commits/web-api/commit-kpis2.php'); | |
| $lines = split("\n", $raw); | |
| $_activeCommitters = array(); | |
| foreach($lines as $line) { | |
| $pair = split(',', $line); | |
| $month = $pair[0]; | |
| $count = $pair[1]; | |
| if (!$month) continue; | |
| if (!$count) continue; | |
| $_activeCommitters[$month] = $count; | |
| } | |
| } | |
| return $_activeCommitters[$period]; | |
| } | |
| function findProposalCount($start, $end) { | |
| global $App; | |
| $sql = "SELECT | |
| count(r.ProposalName) | |
| from ProjectReviews as r | |
| join ProjectReviewStatus as s on (r.id = s.id) | |
| where | |
| s.status = 'Proposal Posted' | |
| and s.value >= date '$start' and s.value < '$end'"; | |
| $result = $App->foundation_sql($sql); | |
| if ($row = mysql_fetch_array($result)) return $row[0]; | |
| return null; | |
| } | |
| ?> |