/** * add an array of field names and their labels to a specified list * @param string listId - unique identifier for the list * @param array fields - an array of arrays containing ['fieldName', $fieldLabel] * @param string fieldLabel - field label */ public function addListFields($listName, $fields = []) { if (is_array($fields) and !empty($fields)) { $listId = self::$lists[$listName]; foreach ($fields as $field) { $result = $this->chimp->lists->mergeVarAdd($listId, strtoupper($field['fieldName']), $field['fieldLabel']); } } sd($result); }
/** * register a single user with MailChimp * @return [type] [description] */ public function subscribe($email, $listName, $mergeData) { try { $result = $this->chimp->lists->subscribe($this->lists[$listName], ['email' => $email], $mergeData, 'html', false, false, true); sd($result); } catch (\Mailchimp_Error $e) { $error = $e->getMessage(); sd($error); } }
function sd($a) { global $ar0; for ($i = 0; $i < count($a); $i++) { if (is_file($a[$i]) !== false) { $ar0[] = filesize($a[$i]); } else { if (is_dir($a[$i]) !== false) { $ar01 = glob("{$a[$i]}/*"); sd($ar01); } } } }
function getData() { $lengths = array(); $cands = array(); $mean = 0; foreach (range(1, 100000) as $j) { $ballot_set_name = 'ballot_' . sprintf("%07d", $j); $dir = substr($ballot_set_name, -3); $filepath = 'sim_ballots_uneven/' . $dir . '/' . $ballot_set_name . '.json'; print "working on {$filepath}\n"; checkIsFile($filepath); $ballots = json_decode(file_get_contents($filepath), 1); foreach ($ballots as $bal) { $lengths[] = count($bal); foreach ($bal as $vote) { if (!isset($cands[$vote])) { $cands[$vote] = 0; } $cands[$vote] += 1; } } if (0 == $j % 10000) { $sum = array_sum($lengths); $mean = $sum / count($lengths); $sd = sd($lengths); } if ($mean) { print "MEAN IS " . $mean . "\n"; print "STANDARD DEVIATION IS " . $sd . "\n"; } } $max_votes = max($cands); $min_votes = min($cands); $results = array(); $results['seats_on_slate'] = $seats; $results['ballot_sets_count'] = 100000; $results['ballot_length_average'] = $mean; $results['ballot_length_standard_deviation'] = $sd; $results['max_candidate_votes'] = $max_votes; $results['min_candidate_votes'] = $min_votes; return $results; }
public function calculate_sd() { $conn = connect_db(); $sql = "SELECT * FROM `course_score`;"; $result = $conn->query($sql); disconnect_db($conn); if ($result->num_rows > 0) { $i = 0; while ($row = $result->fetch_assoc()) { $midterm_scrs[$i] = $row["midterm_score"]; $final_scrs[$i] = $row["final_score"]; $i += 1; } } return array(sd($midterm_scrs), sd($final_scrs)); }
<?php if (c("Form1->controltab")->caption == 1) { $x = c("Form1->pages1")->pageIndex + 1; $namet = "memo"; } if (c("Form1->controltab")->caption == 2) { $x = c("Form1->pages3")->pageIndex + 1; $namet = "tmemo"; } if (c("search->edit1")->text != c("{$namet}{$x}")->selText) { c("search->edit1")->text = c("{$namet}{$x}")->selText; } c("search->checkbox1")->checked = false; sd();
function ViewGroup($id, $measures, $columns, $groupmeasures) { $urllist['Group List'] = "groups.php"; NavigationBar("Groups", $urllist,0,'','','',''); /* get the general group information */ $sqlstring = "select * from groups where group_id = $id"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); $row = mysql_fetch_array($result, MYSQL_ASSOC); $groupname = $row['group_name']; $grouptype = $row['group_type']; ?> <script> $(document).ready(function() { $("#studytable").tablesorter(); } ); </script> <div align="center"><span style="color:darkblue;font-size:15pt;font-weight:bold"><?php echo $groupname; ?> </span> - <i><?php echo $grouptype; ?> </i> level group</div> <br><br> <? /* (subject level) group statistics */ $totalage = 0; $numage = 0; $totalweight = 0; $numweight = 0; $n = 0; //print_r(get_defined_vars()); /* ------------------ subject group type ------------------- */ if ($grouptype == "subject") { /* get the actual group data (subject level) */ $sqlstring = "select a.subjectgroup_id, b.*, (datediff(now(), birthdate)/365.25) 'age' from group_data a left join subjects b on a.data_id = b.subject_id where a.group_id = $id"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; /* do some demographics calculations */ $n++; if ($age > 0) { $totalage += $age; $numage++; $ages[] = $age; } if ($weight > 0) { $totalweight += $weight; $numweight++; $weights[] = $weight; } $genders{$gender}++; $educations{$education}++; $ethnicity1s{$ethnicity1}++; $ethnicity2s{$ethnicity2}++; $handednesses{$handedness}++; } if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; } if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; } if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; } if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; } ?> <table> <tr> <td valign="top" style="padding-right:20px"> <? DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight); ?> </td> </tr> <tr> <td valign="top" style="padding-right:20px"> <details> <summary>SQL</summary> <?php echo PrintSQL($sqlstring); ?> </details> </td> </tr> <tr> <td valign="top"> <form action="groups.php" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?> "> <input type="hidden" name="action" value="removegroupitem"> <table class="smallgraydisplaytable"> <th>Initials</th> <th>UID</th> <th>Age<br><span class="tiny">current</span></th> <th>Sex</th> <th>Ethnicity 1</th> <th>Ethnicity 2</th> <th>Weight</th> <th>Handedness</th> <th>Education</th> <th>Alt UIDs</th> <th>Remove<br>from group</th> <? /* reset the result pointer to 0 to iterate through the results again */ mysql_data_seek($result,0); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $itemid = $row['subjectgroup_id']; $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; /* get list of alternate subject UIDs */ $altuids = GetAlternateUIDs($subjectid); $parts = explode("^",$name); $name = substr($parts[1],0,1) . substr($parts[0],0,1); ?> <tr> <td><?php echo $name; ?> </td> <td><a href="subjects.php?id=<?php echo $subjectid; ?> "><?php echo $uid; ?> </a></td> <? if ($age <= 0) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo number_format($age, 1); ?> Y</td> <? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo $gender; ?> </td> <td><?php echo $ethnicitiy1; ?> </td> <td><?php echo $ethnicitiy1; ?> </td> <td><?php echo number_format($weight, 1); ?> kg</td> <td><?php echo $handedness; ?> </td> <td><?php echo $education; ?> </td> <td><?php echo implode(', ', $altuids); ?> </td> <!--<td><a href="groups.php?action=removegroupitem&itemid=<?php echo $itemid; ?> &id=<?php echo $id; ?> " style="color:red">X</a></td>--> <td><input type="checkbox" name="itemid[]" value="<?php echo $itemid; ?> "></td> </tr> <? } ?> <tr> <td colspan="100" align="right"> <input type="submit" value="Remove"> </form> </td> </tr> </table> </td> </tr> </table> <? } /* ------------------ study group type ------------------- */ if ($grouptype == "study") { $csv = ""; /* get the demographics (study level) */ $sqlstring = "select c.enroll_subgroup,d.*, (datediff(b.study_datetime, d.birthdate)/365.25) 'age' from group_data a left join studies b on a.data_id = b.study_id left join enrollment c on b.enrollment_id = c.enrollment_id left join subjects d on c.subject_id = d.subject_id where a.group_id = $id group by d.uid order by d.uid,b.study_num"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $studyid = $row['study_id']; $studynum = $row['study_num']; $studydesc = $row['study_desc']; $studyalternateid = $row['study_alternateid']; $studymodality = $row['study_modality']; $studydatetime = $row['study_datetime']; $studyoperator = $row['study_operator']; $studyperformingphysician = $row['study_performingphysician']; $studysite = $row['study_site']; $studyinstitution = $row['study_institution']; $studynotes = $row['study_notes']; $subgroup = $row['enroll_subgroup']; $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; $subjectids[] = $subjectid; /* do some demographics calculations */ $n++; if ($age > 0) { $totalage += $age; $numage++; $ages[] = $age; } if ($weight > 0) { $totalweight += $weight; $numweight++; $weights[] = $weight; } $genders{$gender}++; $educations{$education}++; $ethnicity1s{$ethnicity1}++; $ethnicity2s{$ethnicity2}++; $handednesses{$handedness}++; } if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; } if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; } if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; } if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; } if ($measures == "all") { $sqlstringD = "select a.subject_id, b.enrollment_id, c.*, d.measure_name from measures c join measurenames d on c.measurename_id = d.measurename_id left join enrollment b on c.enrollment_id = b.enrollment_id join subjects a on a.subject_id = b.subject_id where a.subject_id in (" . implode2(",", $subjectids) . ")"; //PrintSQL($sqlstringD); $resultD = MySQLQuery($sqlstringD,__FILE__,__LINE__); if ($groupmeasures == "byvalue") { $mnames = array('ANTDX','AVDDX','AX1Com1_Code','AX1Com2_Code','AX1Com3_Code','AX1Com4_Code','AX1Com5_Code','AX1Com6_Code','AX1Com7_Code','AX1Pri_Code','AXIIDX','BRDDX','DPNDX','DSM-Axis','DSM-Axis1','DSM-Axis2','DSM-Axis295.3','DSM-Axis304.3','DSM-AxisV71.09','DSM_IV_TR','DXGROUP_1','DX_GROUP','MiniDxn','MiniDxnFollowUp','NARDX','OBCDX','PARDX','ProbandGroup','Psychosis','relnm1','SAsubtype','SCZDX','status','SubjectType','SZTDX'); while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) { $subjectid = $rowD['subject_id']; $measurename = $rowD['measure_name']; if (in_array($measurename,$mnames)) { if ($rowD['measure_type'] == 's') { $value = strtolower(trim($rowD['measure_valuestring'])); } else { $value = strtolower(trim($rowD['measure_valuenum'])); } if (is_numeric(substr($value,0,6))) { //echo "$value --6--> "; $value = substr($value,0,6); //echo "$value<br>"; } elseif (is_numeric(substr($value,0,5))) { //echo "$value --5--> "; $value = substr($value,0,5); //echo "$value<br>"; } elseif (is_numeric(substr($value,0,4))) { $value = substr($value,0,4); } elseif (is_numeric(substr($value,0,3))) { $value = substr($value,0,3); } elseif (is_numeric(substr($value,1,5))) { $value = substr($value,1,5); } elseif (substr($value,0,3) == "xxx") { $value = "xxx"; } $measuredata[$subjectid][$value] = 1; $measurenames[] = $value; } } $measurenames = array_unique($measurenames); natsort($measurenames); } else { while ($rowD = mysql_fetch_array($resultD, MYSQL_ASSOC)) { if ($rowD['measure_type'] == 's') { $measuredata[$rowD['subject_id']][$rowD['measure_name']]['value'][] = $rowD['measure_valuestring']; } else { $measuredata[$rowD['subject_id']][$rowD['measure_name']]['value'][] = $rowD['measure_valuenum']; } $measuredata[$rowD['subject_id']][$rowD['measure_name']]['notes'][] = $rowD['measure_notes']; $measurenames[] = $rowD['measure_name']; //$i++; } $measurenames = array_unique($measurenames); natcasesort($measurenames); } //PrintVariable($measurenames, 'MeasureNames'); //PrintVariable($measuredata, 'MeasureData'); } /* setup the CSV header */ if ($columns == "min") { $csv = "UID"; } else { $csv = "Initials,UID,AgeAtStudy,Sex,Ethnicity,Race,SubGroup,Weight,Handedness,Education,AltUIDs,StudyID,Description,AltStudyID,Modality,StudyDate,Operator,Physician,Site"; } ?> <table> <tr> <td valign="top" style="padding-right:20px"> <? DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight); ?> </td> </tr> <tr> <td valign="top" style="padding-right:20px"> <details> <summary>SQL</summary> <?php echo PrintSQL($sqlstring); ?> </details> </td> </tr> <tr> <td valign="top"> <a href="groups.php?action=viewgroup&id=<?php echo $id; ?> &measures=all">Include measures</a><br> <a href="groups.php?action=viewgroup&id=<?php echo $id; ?> &measures=all&columns=min">Include measures and only UID</a><br> <a href="groups.php?action=viewgroup&id=<?php echo $id; ?> &measures=all&columns=min&groupmeasures=byvalue">Include measures and only UID and group measures by value</a> <br><br> <span class="tiny">Click columns to sort. May be slow for large tables</span> <form action="groups.php" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?> "> <input type="hidden" name="action" value="removegroupitem"> <table id="studytable" class="tablesorter"> <thead> <tr> <? if ($columns != "min") { ?> <th>Initials</th> <? } ?> <th>UID</th> <? if ($columns != "min") { ?> <th>Age<br><span class="tiny">at study</span></th> <th>Sex</th> <th>Ethnicities</th> <th>SubGroup</th> <th>Weight</th> <th>Handedness</th> <th>Education</th> <th>Alt UIDs</th> <th>Study ID</th> <th>Description</th> <th>Alternate Study ID</th> <th>Modality</th> <th>Date/time</th> <th>Operator</th> <th>Physician</th> <th>Site</th> <? } ?> <? if (count($measurenames) > 0) { foreach ($measurenames as $measurename) { echo "<th>$measurename</th>"; $csv .= ",\"$measurename\""; } } ?> <th>Remove<br>from group</th> </tr> </thead> <tbody> <? /* reset the result pointer to 0 to iterate through the results again */ $sqlstring = "select a.subjectgroup_id, c.enroll_subgroup, b.*, d.*, (datediff(b.study_datetime, d.birthdate)/365.25) 'age' from group_data a left join studies b on a.data_id = b.study_id left join enrollment c on b.enrollment_id = c.enrollment_id left join subjects d on c.subject_id = d.subject_id where a.group_id = $id order by d.uid,b.study_num"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); //mysql_data_seek($result,0); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $studyid = $row['study_id']; $studynum = $row['study_num']; $studydesc = $row['study_desc']; $studyalternateid = $row['study_alternateid']; $studymodality = $row['study_modality']; $studydatetime = $row['study_datetime']; $studyoperator = $row['study_operator']; $studyperformingphysician = $row['study_performingphysician']; $studysite = $row['study_site']; $studyinstitution = $row['study_institution']; $studynotes = $row['study_notes']; $subgroup = $row['enroll_subgroup']; $itemid = $row['subjectgroup_id']; $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; /* get list of alternate subject UIDs */ $altuids = GetAlternateUIDs($subjectid); $parts = explode("^",$name); $name = substr($parts[1],0,1) . substr($parts[0],0,1); if ($columns == "min") { $csv .= "\n\"$uid\""; } else { $csv .= "\n\"$name\",\"$uid\",\"$age\",\"$gender\",\"$ethnicity1\",\"$ethnicity2\",\"$subgroup\",\"$weight\",\"$handedness\",\"$education\",\"" . implode2(', ',$altuids) . "\",\"$uid$studynum\",\"$studydesc\",\"$studyalternateid\",\"$studymodality\",\"$studydatetime\",\"$studyoperator\",\"$studyperformingphysician\",\"$studysite\""; } ?> <tr> <? if ($columns != "min") { ?> <td><?php echo $name; ?> </td> <? } ?> <td><a href="subjects.php?id=<?php echo $subjectid; ?> "><?php echo $uid; ?> </a></td> <? if ($columns != "min") { ?> <? if ($age <= 0) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo number_format($age, 1); ?> Y</td> <? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo $gender; ?> </td> <td style="font-size:8pt"><?php echo $ethnicity1; ?> <?php echo $ethnicity2; ?> </td> <td style="font-size:8pt"><?php echo $subgroup; ?> </td> <? if ($weight <= 0) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo number_format($weight, 1); ?> kg</td> <td><?php echo $handedness; ?> </td> <td><?php echo $education; ?> </td> <td style="font-size:8pt"><?php echo implode2(', ', $altuids); ?> </td> <td><a href="studies.php?id=<?php echo $studyid; ?> "><?php echo $uid; echo $studynum; ?> </a></td> <td style="font-size:8pt"><?php echo $studydesc; ?> </td> <td><?php echo $studyalternateid; ?> </td> <td><?php echo $studymodality; ?> </td> <td><?php echo $studydatetime; ?> </td> <td><?php echo $studyoperator; ?> </td> <td><?php echo $studyperformingphysician; ?> </td> <td style="font-size:8pt"><?php echo $studysite; ?> </td> <? } ?> <? if (count($measurenames) > 0) { if ($groupmeasures == "byvalue") { foreach ($measurenames as $measurename) { $csv .= ",\"" . $measuredata[$subjectid][$measurename] . "\""; ?> <td class="seriesrow"> <? if (isset($measuredata[$subjectid][$measurename])) { echo $measuredata[$subjectid][$measurename]; } ?> </td> <? } } else { foreach ($measurenames as $measure) { $csv .= ",\"" . $measuredata[$subjectid][$measure]['value'] . "\""; ?> <td class="seriesrow"> <? if (isset($measuredata[$subjectid][$measure]['value'])) { foreach ($measuredata[$subjectid][$measure]['value'] as $value) { echo "$value<br>"; } } ?> </td> <? } } } ?> <!--<td><a href="groups.php?action=removegroupitem&itemid=<?php echo $itemid; ?> &id=<?php echo $id; ?> " style="color:red">X</a></td>--> <td><input type="checkbox" name="itemid[]" value="<?php echo $itemid; ?> "></td> </tr> <? } ?> <tr> <td colspan="100" align="right"> <input type="submit" value="Remove"> </form> </td> </tr> </tbody> </table> </td> </tr> </table> <? /* ---------- generate csv file ---------- */ $filename = $groupname . "_" . GenerateRandomString(10) . ".csv"; file_put_contents("/tmp/" . $filename, $csv); ?> <div width="50%" align="center" style="background-color: #FAF8CC; padding: 5px;"> Download .csv file <a href="download.php?type=file&filename=<?php echo "/tmp/{$filename}"; ?> "><img src="images/download16.png"></a> </div> <? } /* ------------------ series group type ------------------- */ if ($grouptype == "series") { /* get a distinct list of modalities... then get a list of series for each modality */ $sqlstring = "select distinct(modality) from group_data where group_id = $id order by modality"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $modalities[] = $row['modality']; } foreach ($modalities as $modality) { $modality = strtolower($modality); /* get the demographics (series level) */ $sqlstring = "select b.*,c.enroll_subgroup, e.*, (datediff(b.series_datetime, e.birthdate)/365.25) 'age' from group_data a left join ".$modality."_series b on a.data_id = b.".$modality."series_id left join studies c on b.study_id = c.study_id left join enrollment d on c.enrollment_id = d.enrollment_id left join subjects e on d.subject_id = e.subject_id where a.group_id = 3 and a.modality = '".$modality."' and e.subject_id is not null group by e.uid"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $studyid = $row['study_id']; $studynum = $row['study_num']; $studydesc = $row['study_desc']; $studyalternateid = $row['study_alternateid']; $studymodality = $row['study_modality']; $studydatetime = $row['study_datetime']; $studyoperator = $row['study_operator']; $studyperformingphysician = $row['study_performingphysician']; $studysite = $row['study_site']; $studyinstitution = $row['study_institution']; $studynotes = $row['study_notes']; $subgroup = $row['enroll_subgroup']; $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; /* do some demographics calculations */ $n++; if ($age > 0) { $totalage += $age; $numage++; $ages[] = $age; } if ($weight > 0) { $totalweight += $weight; $numweight++; $weights[] = $weight; } $genders{$gender}++; $educations{$education}++; $ethnicity1s{$ethnicity1}++; $ethnicity2s{$ethnicity2}++; $handednesses{$handedness}++; } } /* calculate some stats */ if ($numage > 0) { $avgage = $totalage/$numage; } else { $avgage = 0; } if (count($ages) > 0) { $varage = sd($ages); } else { $varage = 0; } if ($numweight > 0) { $avgweight = $totalweight/$numweight; } else { $avgweight = 0; } if (count($weights) > 0) { $varweight = sd($weights); } else { $varweight = 0; } ?> <table> <tr> <td valign="top" style="padding-right:20px"> <? DisplayDemographicsTable($n,$avgage,$varage,$genders,$ethnicity1s,$ethnicity2s,$educations,$handednesses,$avgweight,$varweight); ?> </td> <td valign="top" style="padding-right:20px"> <details> <summary>SQL</summary> <?php echo PrintSQL($sqlstring); ?> </details> </td> <td valign="top"> <table class="smallgraydisplaytable"> <th>Initials</th> <th>UID</th> <th>Age<br><span class="tiny">at study</span></th> <th>Sex</th> <th>Ethnicities</th> <th>SubGroup</th> <th>Weight</th> <th>Handedness</th> <th>Education</th> <th>Alt UIDs</th> <th>Study ID</th> <th>Description/Protocol</th> <th>Modality</th> <th>Date/time</th> <th>Series #</th> <th>Remove<br>from group</th> <? /* get a distinct list of modalities... then get a list of series for each modality */ /* reset the result pointer to 0 to iterate through the results again */ foreach ($modalities as $modality) { $modality = strtolower($modality); /* get the demographics (series level) */ $sqlstring = "select b.*, c.study_num, e.*, (datediff(b.series_datetime, e.birthdate)/365.25) 'age' from group_data a left join ".$modality."_series b on a.data_id = b.".$modality."series_id left join studies c on b.study_id = c.study_id left join enrollment d on c.enrollment_id = d.enrollment_id left join subjects e on d.subject_id = e.subject_id where a.group_id = 3 and a.modality = '".$modality."' and e.subject_id is not null"; //print "[$sqlstring]<br>"; $result = mysql_query($sqlstring) or die("Query failed: " . mysql_error() . "<br><i>$sqlstring</i><br>"); mysql_data_seek($result,0); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $seriesdesc = $row['series_desc']; $seriesprotocol = $row['series_protocol']; $seriesdatetime = $row['series_datetime']; $seriesnum = $row['series_num']; $studynum = $row['study_num']; $seriesmodality = strtoupper($modality); $itemid = $row['subjectgroup_id']; $subjectid = $row['subject_id']; $name = $row['name']; $birthdate = $row['birthdate']; $age = $row['age']; $gender = $row['gender']; $ethnicity1 = $row['ethnicity1']; $ethnicity2 = $row['ethnicity2']; $weight = $row['weight']; $handedness = $row['handedness']; $education = $row['education']; $uid = $row['uid']; /* get list of alternate subject UIDs */ $altuids = GetAlternateUIDs($subjectid); $parts = explode("^",$name); $name = substr($parts[1],0,1) . substr($parts[0],0,1); ?> <tr> <td><?php echo $name; ?> </td> <td><a href="subjects.php?id=<?php echo $subjectid; ?> "><?php echo $uid; ?> </a></td> <? if ($age <= 0) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo number_format($age, 1); ?> Y</td> <? if (!in_array(strtoupper($gender),array('M','F','O'))) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo $gender; ?> </td> <td style="font-size:8pt"><?php echo $ethnicitiy1; ?> <?php echo $ethnicitiy1; ?> </td> <td style="font-size:8pt"><?php echo $subgroup; ?> </td> <? if ($weight <= 0) {$color = "red";} else {$color="black";} ?> <td style="color:<?php echo $color; ?> "><?php echo number_format($weight, 1); ?> kg</td> <td><?php echo $handedness; ?> </td> <td><?php echo $education; ?> </td> <td style="font-size:8pt"><?php echo implode2(', ', $altuids); ?> </td> <td><a href="studies.php?id=<?php echo $studyid; ?> "><?php echo $uid; echo $studynum; ?> </a></td> <td style="font-size:8pt"><?php echo $seriesdesc; ?> <?php echo $seriesprotocol; ?> </td> <td><?php echo $seriesmodality; ?> </td> <td style="font-size:8pt"><?php echo $seriesdatetime; ?> </td> <td><?php echo $seriesnum; ?> </td> <td><a href="groups.php?action=removegroupitem&itemid=<?php echo $itemid; ?> &id=<?php echo $id; ?> " style="color:red">X</a></td> </tr> <? } } ?> </table> </td> </tr> </table> <? } }
function Search($s) { //print_r($s); /* ***************** steps to searching ***************** 1) build the search string 2) run the query 3) depending on the query type, either... a) display the query, then end b) display the results */ /* --------- [1] get the SQL search string ---------- */ $sqlstring = BuildSQLString($s); if ($sqlstring == "") { return; } /* escape all the variables and put them back into meaningful variable names */ foreach ($s as $key => $value) { if (is_scalar($value)) { $$key = mysql_real_escape_string($s[$key]); } else { $$key = $s[$key]; } } /* make modality lower case to conform with table names... MySQL table names are case sensitive when using the 'show tables' command */ $s_studymodality = strtolower($s_studymodality); /* ---------- [2] run the query ----------- */ $starttime = microtime(true); $result = MySQLQuery($sqlstring, __FILE__, __LINE__); $querytime = microtime(true) - $starttime; if ($s_resultorder == "debug") { ?> <span class="sublabel">Query returned <?php echo mysql_num_rows($result); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <div style="background-color: #EEEEEE"><?php echo $sqlstring; ?> </div><br> <div style="background-color: #EEEEEE"><?php echo getFormattedSQL($sqlstring); ?> </div> <br><br><br><br> <? return; } /* display the results */ if (mysql_num_rows($result) > 0) { if ((mysql_num_rows($result) > 100000) && ($s_resultorder != "pipelinecsv")) { ?> <div style="border: 2px solid darkred; background-color: #FFEEEE; text-align: left; padding:5px; border-radius: 5px"> <b>Your search returned <? echo number_format(mysql_num_rows($result),0); ?> results... which is a lot</b> <br> Try changing the search criteria to return fewer results or select a .csv format </div> <? return; } /* generate a color gradient in an array (green to yellow to red) */ $colors = GenerateColorGradient(); $colors2 = GenerateColorGradient2(); /* display the number of rows and the search time */ ?> <span class="sublabel">Query returned <? echo number_format(mysql_num_rows($result),0); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <details> <summary style="font-size:9pt">View SQL query:</summary> <div style="background-color: #EEEEEE; font-family:courier new; font-size:10pt"><?php echo getFormattedSQL($sqlstring); ?> <br></div> </details> <style> #preview { position:absolute; border:1px solid #ccc; background:gray; padding:0px; display:none; color:#fff; } </style> <script type="text/javascript"> // Popup window code function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no') } </script> <? /* ---------- pipeline results ------------ */ if (($s_resultorder == "pipeline") || ($s_resultorder == "pipelinecsv")) { if ($s_pipelineresulttype == "i") { /* get the result names first (due to MySQL bug which prevents joining in this table in the main query) */ $sqlstringX = "select * from analysis_resultnames where result_name like '%$s_pipelineresultname%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultnames[$rowX['resultname_id']] = $rowX['result_name']; } /* and get the result unit (due to the same MySQL bug) */ $sqlstringX = "select * from analysis_resultunit where result_unit like '%$s_pipelineresultunit%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultunit[$rowX['resultunit_id']] = $rowX['result_unit']; } /* ---------------- pipeline results (images) --------------- */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //PrintVariable($row,'row'); $step = $row['analysis_step']; $pipelinename = $row['pipeline_name']; $uid = $row['uid']; $subject_id = $row['subject_id']; $gender = $row['gender']; $study_id = $row['study_id']; $study_num = $row['study_num']; $type = $row['result_type']; $size = $row['result_size']; //$name = $row['result_name']; $name = $resultnames[$row['result_nameid']]; $unit = $resultunit[$row['result_unitid']]; $filename = $row['result_filename']; $swversion = $row['result_softwareversion']; $important = $row['result_isimportant']; $lastupdate = $row['result_lastupdate']; switch($type) { case "v": $thevalue = $value; break; case "f": $thevalue = $filename; break; case "t": $thevalue = $text; break; case "h": $thevalue = $filename; break; case "i": $thevalue = $filename; break; } $tables["$uid$study_num"][$name] = $thevalue; $tables["$uid$study_num"]['subjectid'] = $subject_id; $tables["$uid$study_num"]['studyid'] = $study_id; $tables["$uid$study_num"]['studynum'] = $study_num; $names[$name] = "blah"; } //PrintVariable($tables,'Tables'); ?> <table cellspacing="0" class="multicoltable"> <thead> <tr> <th>UID</th> <? foreach ($names as $name => $blah) { ?> <th align="center" style="font-size:9pt"><?php echo $name; ?> </th> <? } ?> </tr> </thead> <? $maximgwidth = 1200/count($names); $maximgwidth -= ($maximgwidth*0.05); /* subtract 5% of image width to give a gap between them */ if ($maximgwidth < 100) { $maximgwidth = 100; } foreach ($tables as $uid => $valuepair) { ?> <tr style="font-weight: <?php echo $bold; ?> "> <td><a href="studies.php?id=<?php echo $tables[$uid]['studyid']; ?> "><b><?php echo $uid; ?> </b></a></td> <? foreach ($names as $name => $blah) { if ($tables[$uid][$name] == "") { $dispval = "-"; } else { $dispval = $tables[$uid][$name]; } list($width, $height, $type, $attr) = getimagesize("/mount$filename"); $filesize = number_format(filesize("/mount$filename")/1000) . " kB"; ?> <td style="padding:2px"><a href="preview.php?image=/mount<?php echo $dispval; ?> " class="preview"><img src="preview.php?image=/mount<?php echo $dispval; ?> " style="max-width: <?php echo $maximgwidth; ?> px"></a></td> <? } ?> </tr> <? } ?> </table> <br><br><br><br><br><br><br><br> <? } else { /* ---------------- pipeline results (values) --------------- */ /* get the result names first (due to MySQL bug which prevents joining in this table in the main query) */ $sqlstringX = "select * from analysis_resultnames where result_name like '%$s_pipelineresultname%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultnames[$rowX['resultname_id']] = $rowX['result_name']; } /* and get the result unit (due to the same MySQL bug) */ $sqlstringX = "select * from analysis_resultunit where result_unit like '%$s_pipelineresultunit%' "; $resultX = MySQLQuery($sqlstringX,__FILE__,__LINE__); while ($rowX = mysql_fetch_array($resultX, MYSQL_ASSOC)) { $resultunit[$rowX['resultunit_id']] = $rowX['result_unit']; } /* load the data into a useful table */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $step = $row['analysis_step']; $pipelinename = $row['pipeline_name']; $uid = $row['uid']; $subject_id = $row['subject_id']; $study_id = $row['study_id']; $study_num = $row['study_num']; $birthdate = $row['birthdate']; $gender = $row['gender']; $study_datetime = $row['study_datetime']; $type = $row['result_type']; $size = $row['result_size']; $name = $resultnames[$row['result_nameid']]; $name2 = $resultnames[$row['result_nameid']]; $unit = $resultunit[$row['result_unitid']]; $unit2 = $resultunit[$row['result_unitid']]; $text = $row['result_text']; $value = $row['result_value']; $filename = $row['result_filename']; $swversion = $row['result_softwareversion']; $important = $row['result_isimportant']; $lastupdate = $row['result_lastupdate']; /* calculate age at scan */ list($year, $month, $day) = explode("-", $birthdate); $d1 = mktime(0,0,0,$month,$day,$year); list($year, $month, $day, $extra) = explode("-", $study_datetime); $d2 = mktime(0,0,0,$month,$day,$year); $ageatscan = number_format((($d2-$d1)/31536000),1); if (strpos($unit,'^') !== false) { $unit = str_replace('^','<sup>',$unit); $unit .= '</sup>'; } switch($type) { case "v": $thevalue = $value; break; case "f": $thevalue = $filename; break; case "t": $thevalue = $text; break; case "h": $thevalue = $filename; break; case "i": ?> <a href="preview.php?image=/mount<?php echo $filename; ?> " class="preview"><img src="images/preview.gif" border="0"></a> <? break; } if (substr($name, -(strlen($unit))) != $unit) { $name .= " <b>$unit</b>"; $name2 .= " " . $row['result_unit']; } $tables[$uid][$name] = $thevalue; $tables[$uid][$name2] = $thevalue; $tables[$uid]['age'] = $ageatscan; $tables[$uid]['gender'] = $gender; $tables[$uid]['subjectid'] = $subject_id; $tables[$uid]['studyid'] = $study_id; $tables[$uid]['studynum'] = $study_num; //$names[$name] = "blah"; if (($thevalue > $names[$name]['max']) || ($names[$name]['max'] == "")) { $names[$name]['max'] = $thevalue; } if (($thevalue < $names[$name]['min']) || ($names[$name]['min'] == "")) { $names[$name]['min'] = $thevalue; } if (($thevalue > $names2[$name2]['max']) || ($names2[$name2]['max'] == "")) { $names2[$name2]['max'] = $thevalue; } if (($thevalue < $names2[$name2]['min']) || ($names2[$name2]['min'] == "")) { $names2[$name2]['min'] = $thevalue; } } if ($s_resultorder == "pipelinecsv") { $csv = "uid,studynum,sex,age"; foreach ($names2 as $name2 => $blah) { $csv .= ",$name2"; } $csv .= "\n"; foreach ($tables as $uid => $valuepair) { $csv .= $uid . ',' . $tables[$uid]['studynum'] . ',' . $tables[$uid]['gender'] . ',' . $tables[$uid]['age']; foreach ($names2 as $name2 => $blah) { $csv .= ',' . $tables[$uid][$name2]; } $csv .= "\n"; } $filename = "query" . GenerateRandomString(10) . ".csv"; file_put_contents("/tmp/" . $filename, $csv); ?> <br><br> <div width="50%" align="center" style="background-color: #FAF8CC; padding: 5px;"> Download .csv file <a href="download.php?type=file&filename=<?php echo "/tmp/{$filename}"; ?> "><img src="images/download16.png"></a> </div> <? } else { ?> <br><br><br><br><br> <br><br><br><br><br> <br><br><br><br><br> <style> tr.rowhover:hover { background-color: ffff96; } td.tdhover:hover { background-color: yellow; } </style> <table cellspacing="0"> <tr> <td>UID</td> <td>Sex</td> <td>Age</td> <? $csv = "studyid,sex,age"; foreach ($names as $name => $blah) { $csv .= ",$name"; ?> <td style="max-width:25px;"><span style="padding-left: 8px; font-size:10pt; white-space:nowrap; display: block; -webkit-transform: rotate(-70deg) translate3d(0,0,0); -moz-transform: rotate(-70deg);"><?php echo $name; ?> </span></td> <? } $csv .= "\n"; ?> </tr> <? foreach ($tables as $uid => $valuepair) { ?> <tr style="font-weight: <?php echo $bold; ?> " class="rowhover"> <td> <a href="studies.php?id=<?php echo $tables[$uid]['studyid']; ?> "><b><?php echo $uid; ?> </b><?php echo $tables[$uid]['studynum']; ?> </a> </td> <td style="border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:9pt; padding:2px;"><?php echo $tables[$uid]['gender']; ?> </td> <td style="border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:9pt; padding:2px;"><?php echo $tables[$uid]['age']; ?> </td> <? $stats[0][$tables[$uid]['gender']]++; $stats[1][] = $tables[$uid]['age']; $csv .= $tables[$uid]['studyid'] . ',' . $tables[$uid]['gender'] . ',' . $tables[$uid]['age']; $i=2; foreach ($names as $name => $blah) { $val = $tables[$uid][$name]; $range = $names[$name]['max'] - $names[$name]['min']; if (($val > 0) && ($range > 0)) { $cindex = round((($val - $names[$name]['min'])/$range)*100); //echo "[$val, $range, $cindex]<br>"; if ($cindex > 100) { $cindex = 100; } } if ($tables[$uid][$name] == "") { $dispval = "-"; } else { $dispval = $tables[$uid][$name]; $stats[$i][] = $val; //$stats[$i]['numintotal'] ++; } $csv .= ',' . $tables[$uid][$name]; if ($dispval != '-') { if (($dispval + 0) > 10000) { $dispval = number_format($dispval,0); } elseif (($dispval + 0) > 1000) { $dispval = number_format($dispval,2); } else { $dispval = number_format($dispval,4); } } ?> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px; background-color: <? if ($s_pipelinecolorize) { if (trim($dispval) == '-') { echo "#EEE"; } else { echo $colors[$cindex]; } } ?>"><?php echo $dispval; ?> </td> <? $i++; } $csv .= "\n"; ?> </tr> <? } if ($s_pipelineresultstats == 1) { ?> <tr class="rowhover"> <td align="right"><b>N</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"> <? foreach ($stats[0] as $key => $value) { echo "$key -> $value<br>"; } ?> </td> <? for($i=1;$i<count($stats);$i++) { $count = count($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $count; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Min</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $min = min($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $min; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Max</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $max = max($stats[$i]); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $max; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Mean</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $avg = number_format(array_sum($stats[$i])/count($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $avg; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Median</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $median = number_format(median($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $median; ?> </td><? } ?> </tr> <tr class="rowhover"> <td align="right"><b>Std Dev</b></td> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"></td> <? for($i=1;$i<count($stats);$i++) { $stdev = number_format(sd($stats[$i]),2); ?><td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px;"><?php echo $stdev; ?> </td><? } ?> </tr> <? } ?> </table> <? if ($s_pipelinecormatrix == 1) { ?> <br><br><br><br> <br><br><br><br> <b>Correlation Matrix (r)</b><br> <? foreach ($names as $name => $blah) { foreach ($tables as $uid => $valuepair) { $lists['age'][] = $tables[$uid]['age']; /* this loop gets the data into an array */ foreach ($names as $name => $blah) { $lists[$name][] = $tables[$uid][$name]; } } } ?> <table cellspacing="0"> <tr> <td> </td> <? foreach ($lists as $label => $vals1) { ?> <td style="max-width:25px;"><span style="padding-left: 8px; font-size:10pt; white-space:nowrap; display: block; -webkit-transform: rotate(-70deg) translate3d(0,0,0); -moz-transform: rotate(-70deg);"><?php echo $label; ?> </span></td> <? } ?> </tr> <? $kashi = new Kashi(); foreach ($lists as $label => $vals1) { for ($i=0;$i<count($vals1);$i++) { if ($vals1[$i] == 0) { $vals1[$i] = 0.000001; } } ?> <tr class="rowhover"> <td align="right" style="font-size:10pt"><?php echo $label; ?> </td> <? foreach ($lists as $label => $vals2) { $starttime1 = microtime(true); /* compare vals1 to vals2 */ //$coeff = Correlation($vals1,$vals2); for ($i=0;$i<count($vals2);$i++) { if ($vals2[$i] == 0) { $vals2[$i] = 0.000001; } } $coeff = $kashi->cor($vals1,$vals2); $coefftime = microtime(true) - $starttime1; $cindex = round((($coeff - (-1))/2)*100); //echo "[$val, $range, $cindex]<br>"; if ($cindex > 100) { $cindex = 100; } /* display correlation coefficient */ ?> <td class="tdhover" style="text-align: right; border-left: 1px solid #AAAAAA; border-top: 1px solid #AAAAAA; font-size:8pt; padding:2px; background-color: <?php echo $colors2[$cindex]; ?> "><?php echo number_format($coeff, 3); ?> </td> <? flush(); } ?> </tr> <? } ?> </table> <? } } } } elseif ($s_resultorder == 'subject') { /* display only subject data */ SearchStudy($result); } elseif ($s_resultorder == 'uniquesubject') { /* display only unique subject data */ SearchSubject($result); } elseif ($s_resultorder == 'long') { /* display longitudinal data */ SearchLongitudinal($result); } else { SearchDefault($result, $s, $colors, $colors2); } } else { ?> <span class="sublabel">Query returned <? echo number_format(mysql_num_rows($result),0); ?> rows in <?php echo number_format($querytime, 4); ?> sec</span> <details> <summary style="font-size:9pt">View SQL query:</summary> <div style="background-color: #EEEEEE; font-family:courier new; font-size:10pt"><?php echo getFormattedSQL($sqlstring); ?> <br></div> </details> <br> <? } }
public function show() { sd(Input::all()); }
public function topics() { sd(Input::all()); }
function sharpe_ratio($days) { $karma = array_sum($days); return $karma/(count($days)*sd($days)); }
function d($var, $name = false) { echo sd($var, $name); }
public static function getResultStandardDeviation($data, $obj) { $value = 0; if (count($data) <= 1) { return $value; //TODO: Handle cases where amount of data returned is less than expected } $historical_data = array_slice($data, 0, count($data) - 1); return sd($historical_data); }
function SearchLongitudinalPipeline(&$result, $s_resultorder) { //PrintSQLTable($result); if ($s_resultorder == 'pipelinelong') { $agebin = 'M'; } else { $agebin = 'Y'; } $modality = ''; $i = 0; /* gather scans into longitudinal format */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $uid = strtoupper(trim($row['uid'])); $encuid = crc32(strtoupper(trim($row['uid']))); $studyid = $row['study_id']; #$studynum = $row['study_num']; $sex = $row['gender']; $age = $row['ageinmonths']; #$seriesdesc = $row['series_desc']; $resultname = $row['result_nameid']; $resultvalue = $row['result_value']; $series[] = $resultname; # exclude anyone under 0yr or over 100yrs if ($age > 0 && $age < 1200) { $longs[$age][$resultname][] = $resultvalue; } $exportdata[$resultname][$studyid]['age'] = $age; $exportdata[$resultname][$studyid]['value'] = $resultvalue; $exportdata[$resultname][$studyid]['sex'] = $sex; $i++; } $series = array_unique($series); sort($series); ksort($longs); //echo "<pre>"; //print_r($exportdata); //echo "</pre>"; //exit(0); /* get the month ranges */ $thekeys = array_keys($longs); $minage = $thekeys[0]; $maxage = end($thekeys); echo "Age range in months [{$minage}] to [{$maxage}]<br>"; $csv1 = "uid"; $csv2 = "uid"; /* loop through the age bins and calculate stats on each bin */ foreach ($longs as $bin => $val) { /* loop through the SeriesDescriptions */ foreach ($val as $resultid => $values) { $mean = array_sum($values) / count($values); $count = count($values); $min = min($values); $max = max($values); $stdev = sd($values); $summary[$bin][$resultid]['mean'] = $mean; $summary[$bin][$resultid]['count'] = $count; $summary[$bin][$resultid]['min'] = $min; $summary[$bin][$resultid]['max'] = $max; $summary[$bin][$resultid]['stdev'] = $stdev; } } //echo "<pre>"; //print_r($summary); //echo "</pre>"; foreach ($series as $resultid) { ?> result ID [<?php echo $resultid; ?> ]<br> <table cellspacing="0" style="font-size: 8pt" border="1"> <tr> <td>Bin (months)</td> <td>Count</td> <td>min</td> <td>max</td> <td>stdev</td> <td>Mean</td> </tr> <?php foreach ($summary as $bin => $values) { $mean = $values[$resultid]['mean']; $count = $values[$resultid]['count']; $min = $values[$resultid]['min']; $max = $values[$resultid]['max']; $stdev = $values[$resultid]['stdev']; ?> <tr> <td align="right" style="color:darkblue"><?php echo $bin; ?> </td> <td align="right" style="color:darkblue"><?php echo $count; ?> </td> <td align="right" style="color:darkblue"><?php echo $min; ?> </td> <td align="right" style="color:darkblue"><?php echo $max; ?> </td> <td align="right" style="color:darkblue"><?php echo $stdev; ?> </td> <td align="right" style="color:darkblue"><?php echo $mean; ?> </td> </tr> <?php } ?> </table> <?php } $csv = "ID, age, sex, ROI, value\n"; foreach ($exportdata as $resultid => $subject) { foreach ($subject as $uid => $values) { $age = $values['age']; $sex = $values['sex']; $value = $values['value']; $csv .= "{$uid}, {$age}, {$sex}, {$resultid}, {$value}\n"; } } ?> </table> Full table .csv<br> <textarea rows="8" cols="150"><?php echo $csv; ?> </textarea> <?php }
function aggregate($arr, $p, $groupname = 'left', $attr = NULL) { /* Calculate aggregate values * * Currently recognized aggregates: * avg: average * stddev: standard deviation * stddev+: average + standard deviation * stddev-: average - standard deviation */ if (!is_array($arr) || !count($arr)) { return array(); } if (!is_array($p)) { $p = array($p); } $full = array(); $rv = array(); foreach ($arr[0]->points() as $ts) { $sum = 0; $nonnull = 0; foreach ($arr as $sets) { if ($sets->groupname() != $groupname) { continue; } $value = $sets->data($ts, $attr); if ($value != "") { $nonnull = 1; } $sum += $value; } if ($nonnull == 1) { $full[] = $sum; } } if (in_array('avg', $p) && count($full) > 0) { $rv['avg'] = array_sum($full) / count($full); } if (in_array('stddev', $p) || in_array('stddev+', $p) || in_array('stddev-', $p)) { function sd_square($x, $mean) { return pow($x - $mean, 2); } function sd($array) { if (count($array) > 0) { // make sure we do not divide by zero return sqrt(array_sum(array_map("sd_square", $array, array_fill(0, count($array), array_sum($array) / count($array)))) / (count($array) - 1)); } else { return 0; } } $stddev = sd($full); if (in_array('stddev', $p)) { $rv['stddev'] = $stddev; } if (in_array('stddev+', $p)) { if (empty($rv['avg']) && count($full) > 0) { $avg = array_sum($full) / count($full); } else { $avg = $rv['avg']; } $rv['stddev+'] = $avg + $stddev; } if (in_array('stddev-', $p)) { if (empty($rv['avg']) && count($full) > 0) { $avg = array_sum($full) / count($full); } else { $avg = $rv['avg']; } $rv['stddev-'] = $avg - $stddev; } } return $rv; }
echo $exact; ?> " name="" class="frm-ignore form-control frm-setX1" type="text" placeholder=""></span></td> <td class="td-center"><span class="input"><input tabindex="999999" readonly="readonly" id="" value="<?php echo $exact; ?> " name="" class="frm-ignore form-control frm-setX2" type="text" placeholder=""></span></td> </tr> <tr class="row-x"> <td style="vertical-align:middle;width:25%" class="td-center" colspan="2">Incertidumbre</td> <td class="td-center"><span class="input"><input tabindex="999999" readonly="readonly" id="" value="<?php echo round(sd($max1) * 2, $globalDec); ?> " name="" class="frm-ignore form-control frm-setX1" type="text" placeholder=""></span></td> <td class="td-center"><span class="input"><input tabindex="999999" readonly="readonly" id="" value="<?php echo round(sd($max2) * 2, $globalDec); ?> " name="" class="frm-ignore form-control frm-setX2" type="text" placeholder=""></span></td> </tr> </tbody> </table> <?php } ?> <?php $resultX = false; ?> <?php if (!$dataItem['outofuse']) { ?> <?php
/** * request the send of a transactional email * @return null */ public function transactionEmail(\App\V1\Mailers\Mandrill $mailer) { $data = ["email" => "*****@*****.**", "name" => "Paul Schneider"]; sd($mailer->send(new \App\V1\Mailers\Mandrill\Unsubscribeable($data))); }
public function getTimezoneActivity($corpArray) { if (!is_array($corpArray)) { return false; } $tzActivityArray = array(); foreach ($corpArray as $aCorp) { // Add this corps TZ activity. Note: Kills and losses are treated the same // - we just want to know when they are active if (is_array($corpActivityDB = $this->getKillsInvolvingCorporation($aCorp))) { foreach ($corpActivityDB as $aCorpA) { $tzActivityArray[] = $aCorpA["kill"]->timestamp; } } } // Calculate TZ spread. Note: This is based on people working during the day, and // is weighted towards the mid to upper end (prime time). Note also that EVE // timestamps are constant - adjustments have to be made for timezones. The // calculations are not binary, a kill at midnight EVE time would be prime time // US, and still within EU. $tzArray = array("eu" => array("name" => "Euro", "score" => 0, "z-score" => 0, "r-perc" => 0, "z-perc" => 0, "shift" => 1), "us" => array("name" => "US", "score" => 0, "z-score" => 0, "r-perc" => 0, "z-perc" => 0, "shift" => -5), "au_nz" => array("name" => "AU/NZ", "score" => 0, "z-score" => 0, "r-perc" => 0, "z-perc" => 0, "shift" => 10)); $tzWeight = array(0 => 0.35, 1 => 0.1, 2 => 0.05, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0.05, 12 => 0.1, 13 => 0.1, 14 => 0.1, 15 => 0.1, 16 => 0.1, 17 => 0.1, 18 => 0.2, 19 => 0.45, 20 => 0.7, 21 => 0.9, 22 => 1.0, 23 => 0.7); foreach ($tzActivityArray as $aTime) { // 6pm to midnight is the spread for everyone //dprintf("kill time: %s, EU: %s, US: %s, AU/NZ: %s", $aTime, date("H:i:s", strtotime("+1 hour", strtotime($aTime))), date("H:i:s", strtotime("-5 hours", strtotime($aTime))), date("H:i:s", strtotime("+10 hours", strtotime($aTime)))); $eTZhour = intval(date("G", strtotime("+1 hour", strtotime($aTime)))); $eUShour = intval(date("G", strtotime("-5 hours", strtotime($aTime)))); $eAUhour = intval(date("G", strtotime("+10 hours", strtotime($aTime)))); $tzArray["eu"]["score"] += $tzWeight[$eTZhour] + abs($tzWeight[$eTZhour + 1 > 23 ? 0 : $eTZhour + 1] - $tzWeight[$eTZhour]) * (intval(date("i", strtotime($aTime))) / 59 * 100); $tzArray["us"]["score"] += $tzWeight[$eUShour] + abs($tzWeight[$eUShour + 1 > 23 ? 0 : $eUShour + 1] - $tzWeight[$eUShour]) * (intval(date("i", strtotime($aTime))) / 59 * 100); $tzArray["au_nz"]["score"] += $tzWeight[$eAUhour] + abs($tzWeight[$eAUhour + 1 > 23 ? 0 : $eAUhour + 1] - $tzWeight[$eAUhour]) * (intval(date("i", strtotime($aTime))) / 59 * 100); } // Calculate TZ percentiles $tzZAry = array($tzArray["eu"]["score"], $tzArray["us"]["score"], $tzArray["au_nz"]["score"]); $tzStdDev = sd($tzZAry); $tzArray["eu"]["z-score"] = ($tzArray["eu"]["score"] - array_sum($tzZAry) / 3) / $tzStdDev; $tzArray["eu"]["z-perc"] = cdf($tzArray["eu"]["z-score"]) * 100; $tzArray["eu"]["r-perc"] = $tzArray["eu"]["score"] / array_sum($tzZAry) * 100; $tzArray["us"]["z-score"] = ($tzArray["us"]["score"] - array_sum($tzZAry) / 3) / $tzStdDev; $tzArray["us"]["z-perc"] = cdf($tzArray["us"]["z-score"]) * 100; $tzArray["us"]["r-perc"] = $tzArray["us"]["score"] / array_sum($tzZAry) * 100; $tzArray["au_nz"]["z-score"] = ($tzArray["au_nz"]["score"] - array_sum($tzZAry) / 3) / $tzStdDev; $tzArray["au_nz"]["z-perc"] = cdf($tzArray["au_nz"]["z-score"]) * 100; $tzArray["au_nz"]["r-perc"] = $tzArray["au_nz"]["score"] / array_sum($tzZAry) * 100; // Sort array by score descending $aryScore = array(); foreach ($tzArray as $key => $row) { $aryScore[$key] = $row["score"]; } array_multisort($aryScore, SORT_DESC, $tzArray); return $tzArray; }