lastErr = null; } public function getFolderKey() { return $this->folderKey; } public function parseFile($filename) { if (!self::open($filename)) { return false; } $this->lastErr = null; $this->firstDate = "2170-01-01"; $this->lastDate = "1970-01-01"; $this->users = array(); $this->totalTime = 0; $this->workspaces = array(); while ($row = self::getRow()) { if (!isset($this->workspaces[$row->workspace])) $this->workspaces[$row->workspace] = array(); $this->workspaces[$row->workspace][] = $row; self::incrementTime($row); } self::close(); return true; } public function saveImportCsv() { $links = array(); $headers = array('User', 'Email', 'Client', 'Project', 'Description', 'Start date', 'Start time', 'Duration'); $this->folderKey = $this->firstDate . '_' . $this->lastDate; $dir = "converted/{$this->folderKey}/"; $this->deleteDir($dir); $old_umask = umask(0); mkdir($dir, 0775, true); umask($old_umask); foreach ($this->workspaces as $workspace => $data) { $filename = $dir . $workspace . ".csv"; $file = fopen($filename, "w+"); fputcsv($file, $headers); foreach ($data as $row) { $csvRow = array($row->user, $row->email, $row->client, $row->project, $row->description, $row->startDate, $row->startTime, $row->duration); fputcsv($file, $csvRow); } fclose($file); $links[] = $filename; } return $links; } public function getUsers() { return $this->users; } public function getWorkspace($ws) { return isset($this->workspaces[$ws]) ? $this->workspaces[$ws] : array(); } public function getNumEntries() { $count = 0; foreach ($this->workspaces as $data) { $count += count($data); } return $count; } public function getTotalTime($stringFormat = true) { if ($stringFormat) { $hours = floor($this->totalTime / 3600); $mins = floor($this->totalTime / 60 % 60); $secs = floor($this->totalTime % 60); return sprintf('%02d:%02d:%02d', $hours, $mins, $secs); } return $this->totalTime; } private function deleteDir($dirPath) { if (!is_dir($dirPath)) { return; } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { self::deleteDir($file); } else { unlink($file); } } rmdir($dirPath); } private function getRow() { $data = fgetcsv($this->file); if (!$data) { return false; } $row = new stdClass(); $row->user = $data[0]; $row->email = $data[1]; $row->workspace = null; $row->client = null; $row->project = null; $row->description = null; $row->startDate = $data[7]; $row->startTime = $data[8]; $row->duration = $data[11]; if (strtotime($row->startDate) < strtotime($this->firstDate)) { $this->firstDate = $row->startDate; } if (strtotime($row->startDate) > strtotime($this->lastDate)) { $this->lastDate = $row->startDate; } if (!in_array($row->user, $this->users)) { $this->users[] = $row->user; } self::convert($row, $data[3], $data[5]); return $row; } private function convert($row, $project, $desc) { // we do this because humans are bad at follwing orders $desc = str_replace('SRV_ ', 'SRV_', $desc); list($subProject, $description) = preg_split('/(\s|:)/', trim($desc), 2); //list($subProject, $description) = explode(':', $desc, 2); //$subProject = strtolower(str_replace(' ', '', $subProject)); $subProject = strtolower($subProject); $row->description = trim($description); $matches = null; // SunPower Workspace if ($project == "SunPower") { $row->workspace = "SunPower"; // OASIS if (preg_match('/sp_o3_srv_rm(\d+)/', $subProject, $matches)) { $row->client = 'OASIS'; $row->project = 'RM ' . sprintf('%03d', $matches[1]); } else if (preg_match('/sp_o3_sc_rm(\d+)/', $subProject, $matches)) { $row->client = 'OASIS'; $row->project = 'SC RM ' . sprintf('%02d', $matches[1]); } else if ($subProject == 'sp_o3_overhead') { $row->client = 'OASIS'; $row->project = 'SC #Overhead'; } else if ($subProject == 'sp_o3_unknown') { $row->client = 'OASIS'; $row->project = 'SC #Unknown'; } else if ($subProject == 'sp_edp') { $row->client = 'OASIS'; $row->project = 'Research Spike'; } // TMAC else if ($subProject == 'sp_tmac' || $subProject == 'tmac') { $row->client = 'TMAC'; $row->project = 'TMAC Engineering'; } else if ($subProject == 'sp_tmac_china' || $subProject == 'tmac_china') { $row->client = 'TMAC'; $row->project = 'TMAC Engineering China'; } else if ($subProject == 'sp_tmac_overhead' || $subProject == 'tmac_overhead') { $row->client = 'TMAC'; $row->project = 'Overhead'; } else if ($subProject == 'sp_tmac_unknown' || $subProject == 'tmac_unknown') { $row->client = 'TMAC'; $row->project = 'Unknown'; } // EDDiE else if ($subProject == 'eddie_off_spec') { $row->client = 'EDDiE'; $row->project = 'Off-Spec Requests'; } else if ($subProject == 'eddie_overhead') { $row->client = 'EDDiE'; $row->project = 'Overhead'; } else if ($subProject == 'eddie_unknown') { $row->client = 'EDDiE'; $row->project = 'Unknown'; } else if ($subProject == 'eddie_kickoff') { $row->client = 'EDDiE'; $row->project = 'Kickoff'; } else if ($subProject == 'eddie_manual_mode') { $row->client = 'EDDiE'; $row->project = 'Manual Mode Tasks'; } // HELIX else if ($subProject == 'helix_off_spec') { $row->client = 'HELIX'; $row->project = 'Off-Spec Requests'; } else if ($subProject == 'helix_overhead') { $row->client = 'HELIX'; $row->project = 'Overhead'; } else if ($subProject == 'helix_unknown') { $row->client = 'HELIX'; $row->project = 'Unknown'; } else if ($subProject == 'helix_kickoff') { $row->client = 'HELIX'; $row->project = 'Kickoff'; } else if ($subProject == 'helix_task_01') { $row->client = 'HELIX'; $row->project = 'TASK 01: Internal Server Error Debug'; } else if ($subProject == 'helix_task_02') { $row->client = 'HELIX'; $row->project = 'TASK 02: Automatic Windzones Bug'; } else if ($subProject == 'helix_task_03') { $row->client = 'HELIX'; $row->project = 'TASK 03: Aurora File Format Change'; } else if ($subProject == 'helix_task_04') { $row->client = 'HELIX'; $row->project = 'TASK 04: File Upload Timeout Bug'; } else if ($subProject == 'helix_task_05') { $row->client = 'HELIX'; $row->project = 'TASK 05: Swap Monitoring Units in BOM'; } else if ($subProject == 'helix_task_06') { $row->client = 'HELIX'; $row->project = 'TASK 06: Improve File Validation for File Uploads'; } else if ($subProject == 'helix_task_07') { $row->client = 'HELIX'; $row->project = 'TASK 07: Link-tray Counts Aren\'t Accurate'; } else if ($subProject == 'helix_task_08') { $row->client = 'HELIX'; $row->project = 'TASK 08: Resolve Timeout Error on File Upload'; } else if ($subProject == 'helix_task_09') { $row->client = 'HELIX'; $row->project = 'TASK 09: Windzones Error for L-Shaped Buildings'; } else if ($subProject == 'helix_task_10') { $row->client = 'HELIX'; $row->project = 'TASK 10: Seismic Anchor Bug'; } else if ($subProject == 'helix_task_11') { $row->client = 'HELIX'; $row->project = 'TASK 11: 150 Foot Bug'; } else if ($subProject == 'helix_task_11') { $row->client = 'HELIX'; $row->project = 'TASK 11: 150 Foot Bug'; /** Skipped Some **/ } else if ($subProject == 'helix_task_17') { $row->client = 'HELIX'; $row->project = 'TASK 17: Add Delta Inverters to the Database'; } else if ($subProject == 'helix_task_18') { $row->client = 'HELIX'; $row->project = 'TASK 18: Inverter Selection on Power Station Config'; } // Communities else if($subProject == 'sp_comm_phase_1') { $row->client = 'Communities'; $row->project = 'Phase I Pivotal Stories - Development'; } else if($subProject == 'sp_comm_kickoff') { $row->client = 'Communities'; $row->project = 'Kickoff'; } else if($subProject == 'sp_comm_pm_oh') { $row->client = 'Communities'; $row->project = 'PM Overhead'; } else if($subProject == 'sp_comm_team_oh') { $row->client = 'Communities'; $row->project = 'Team Overhead'; } // Analytics Fire Workspace if ($row->client == null) { $row->workspace = 'Analytics Fire'; if (($subProject == 'af_overhead') || ($subProject == 'af_unknown')) { $row->client = 'Analytics Fire'; $row->project = 'Other'; } else if ($subProject == 'af_hiring') { $row->client = 'Analytics Fire'; $row->project = 'Hiring'; } else if ($subProject == 'af_r&d') { $row->client = 'Analytics Fire'; $row->project = 'Research & Development'; } else if ($subProject == 'af_rfp') { $row->client = 'Analytics Fire'; $row->project = 'Opportunity Development / RFP'; } } } // Analytics Fire Workspace (explicit) if ($project == 'AnalyticsFire' || $project == 'Analytics Fire' || $project == 'Analytics Fire R&D') { $row->workspace = 'Analytics Fire'; if (($subProject == 'af_overhead') || ($subProject == 'af_unknown')) { $row->client = 'Analytics Fire'; $row->project = 'Other'; } else if ($subProject == 'af_hiring') { $row->client = 'Analytics Fire'; $row->project = 'Hiring'; } else if ($subProject == 'af_r&d') { $row->client = 'Analytics Fire'; $row->project = 'Research & Development'; } else if ($subProject == 'af_rfp') { $row->client = 'Analytics Fire'; $row->project = 'Opportunity Development / RFP'; } } // SunPower: Helix (explicit) if ($project == 'Helix') { $row->workspace = "SunPower"; if ($subProject == 'helix_off_spec') { $row->client = 'HELIX'; $row->project = 'Off-Spec Requests'; } else if ($subProject == 'helix_overhead') { $row->client = 'HELIX'; $row->project = 'Overhead'; } else if ($subProject == 'helix_unknown') { $row->client = 'HELIX'; $row->project = 'Unknown'; } else if ($subProject == 'helix_kickoff') { $row->client = 'HELIX'; $row->project = 'Kickoff'; } else if ($subProject == 'helix_task_01') { $row->client = 'HELIX'; $row->project = 'TASK 01: Internal Server Error Debug'; } else if ($subProject == 'helix_task_02') { $row->client = 'HELIX'; $row->project = 'TASK 02: Automatic Windzones Bug'; } else if ($subProject == 'helix_task_03') { $row->client = 'HELIX'; $row->project = 'TASK 03: Aurora File Format Change'; } else if ($subProject == 'helix_task_04') { $row->client = 'HELIX'; $row->project = 'TASK 04: File Upload Timeout Bug'; } else if ($subProject == 'helix_task_05') { $row->client = 'HELIX'; $row->project = 'TASK 05: Swap Monitoring Units in BOM'; } else if ($subProject == 'helix_task_06') { $row->client = 'HELIX'; $row->project = 'TASK 06: Improve File Validation for File Uploads'; } else if ($subProject == 'helix_task_07') { $row->client = 'HELIX'; $row->project = 'TASK 07: Link-tray Counts Aren\'t Accurate'; } else if ($subProject == 'helix_task_08') { $row->client = 'HELIX'; $row->project = 'TASK 08: Resolve Timeout Error on File Upload'; } else if ($subProject == 'helix_task_09') { $row->client = 'HELIX'; $row->project = 'TASK 09: Windzones Error for L-Shaped Buildings'; } else if ($subProject == 'helix_task_10') { $row->client = 'HELIX'; $row->project = 'TASK 10: Seismic Anchor Bug'; } else if ($subProject == 'helix_task_11') { $row->client = 'HELIX'; $row->project = 'TASK 11: 150 Foot Bug'; /** Skipped Some **/ } else if ($subProject == 'helix_task_17') { $row->client = 'HELIX'; $row->project = 'TASK 17: Add Delta Inverters to the Database'; } else if ($subProject == 'helix_task_18') { $row->client = 'HELIX'; $row->project = 'TASK 18: Inverter Selection on Power Station Config'; } } // ICracked Workspace if ($project == 'iCracked') { $row->workspace = 'iCracked'; $row->client = 'iCracked'; $row->project = 'Out of Scope Requests'; } // Arthrex if ($project == 'Arthrex') { $row->workspace = "Arthrex"; if ($subProject == 'arthrex_overhead') { $row->client = 'UI Port - Streaming Video UI'; $row->project = 'Team Overhead'; } else if ($subProject == 'arthrex_devops') { $row->client = 'UI Port - Streaming Video UI'; $row->project = 'DevOps'; } else if ($subProject == 'arthrex_unknown') { $row->client = 'UI Port - Streaming Video UI'; $row->project = 'Unknown'; } } // No match? Null it out if ($row->client == null) { $row->workspace = 'Unknown'; $row->description = $desc; $row->client = null; $row->project = null; } } private function incrementTime($row) { list($hours, $minutes, $seconds) = explode(':', $row->duration); $seconds = intval($seconds); $minutes = intval($minutes) * 60; $hours = intval($hours) * 3600; $this->totalTime += $hours + $minutes + $seconds; } }