Skip to content

Instantly share code, notes, and snippets.

@agustinhaller
Last active January 4, 2016 04:28
Show Gist options
  • Select an option

  • Save agustinhaller/8568345 to your computer and use it in GitHub Desktop.

Select an option

Save agustinhaller/8568345 to your computer and use it in GitHub Desktop.
Add Python Tests to truly.am testing framework
<?php
$test_results = array(array('sample' => 'agus', 'subject' => 'dayu', 'confidence' => '5.32442375'),
array('sample' => 'chapman', 'subject' => 'dayu', 'confidence' => '431.866991'),
array('sample' => 'dayu', 'subject' => 'dayu', 'confidence' => '283.407861'),
array('sample' => 'alex', 'subject' => 'dayu', 'confidence' => '455.675758'),
array('sample' => 'ali', 'subject' => 'dayu', 'confidence' => '150.218559'),
array('sample' => 'shayan', 'subject' => 'dayu', 'confidence' => '395.017484'),
array('sample' => 's1', 'subject' => 'dayu', 'confidence' => '92.1327915'),
array('sample' => 's2', 'subject' => 'dayu', 'confidence' => '119.563628'),
array('sample' => 's3', 'subject' => 'dayu', 'confidence' => '99.4542037'),
array('sample' => 's4', 'subject' => 'dayu', 'confidence' => '834.649317'),
array('sample' => 'agus', 'subject' => 'chapman', 'confidence' => '151.723786'),
array('sample' => 'chapman', 'subject' => 'chapman', 'confidence' => '44.6698122'),
array('sample' => 'dayu', 'subject' => 'chapman', 'confidence' => '210.342768'),
array('sample' => 'alex', 'subject' => 'chapman', 'confidence' => '28.7077334'),
array('sample' => 'ali', 'subject' => 'chapman', 'confidence' => '84.0752619'),
array('sample' => 'shayan', 'subject' => 'chapman', 'confidence' => '165.495668'),
array('sample' => 's1', 'subject' => 'chapman', 'confidence' => '197.971180'),
array('sample' => 's2', 'subject' => 'chapman', 'confidence' => '73.7315721'),
array('sample' => 's3', 'subject' => 'chapman', 'confidence' => '164.971974'),
array('sample' => 's4', 'subject' => 'chapman', 'confidence' => '51.7894291'),
array('sample' => 'agus', 'subject' => 'ali', 'confidence' => '14.7406725'),
array('sample' => 'chapman', 'subject' => 'ali', 'confidence' => '118.322940'),
array('sample' => 'dayu', 'subject' => 'ali', 'confidence' => '28.8319602'),
array('sample' => 'alex', 'subject' => 'ali', 'confidence' => '77.0131403'),
array('sample' => 'ali', 'subject' => 'ali', 'confidence' => '13.5680823'),
array('sample' => 'shayan', 'subject' => 'ali', 'confidence' => '57.4103232'),
array('sample' => 's1', 'subject' => 'ali', 'confidence' => '18.5325984'),
array('sample' => 's2', 'subject' => 'ali', 'confidence' => '45.0615838'),
array('sample' => 's3', 'subject' => 'ali', 'confidence' => '26.6460500'),
array('sample' => 's4', 'subject' => 'ali', 'confidence' => '70.3213219'),
array('sample' => 'agus', 'subject' => 'shayan', 'confidence' => '46.9720447'),
array('sample' => 'chapman', 'subject' => 'shayan', 'confidence' => '72.3736530'),
array('sample' => 'dayu', 'subject' => 'shayan', 'confidence' => '97.5963068'),
array('sample' => 'alex', 'subject' => 'shayan', 'confidence' => '21.8888235'),
array('sample' => 'ali', 'subject' => 'shayan', 'confidence' => '5.44356779'),
array('sample' => 'shayan', 'subject' => 'shayan', 'confidence' => '39.4120973'),
array('sample' => 's1', 'subject' => 'shayan', 'confidence' => '57.0040390'),
array('sample' => 's2', 'subject' => 'shayan', 'confidence' => '21.9485550'),
array('sample' => 's3', 'subject' => 'shayan', 'confidence' => '45.3651908'),
array('sample' => 's4', 'subject' => 'shayan', 'confidence' => '23.4579013'),
array('sample' => 'agus', 'subject' => 's2', 'confidence' => '2493.07825'),
array('sample' => 'chapman', 'subject' => 's2', 'confidence' => '3180.71532'),
array('sample' => 'dayu', 'subject' => 's2', 'confidence' => '3157.75077'),
array('sample' => 'alex', 'subject' => 's2', 'confidence' => '3051.41795'),
array('sample' => 'ali', 'subject' => 's2', 'confidence' => '2284.11080'),
array('sample' => 'shayan', 'subject' => 's2', 'confidence' => '3100.26950'),
array('sample' => 's1', 'subject' => 's2', 'confidence' => '1514.17597'),
array('sample' => 's2', 'subject' => 's2', 'confidence' => '1851.00968'),
array('sample' => 's3', 'subject' => 's2', 'confidence' => '1987.33908'),
array('sample' => 's4', 'subject' => 's2', 'confidence' => '2279.57119'),
array('sample' => 'agus', 'subject' => 's3', 'confidence' => '1820.49236'),
array('sample' => 'chapman', 'subject' => 's3', 'confidence' => '2647.75103'),
array('sample' => 'dayu', 'subject' => 's3', 'confidence' => '794.440231'),
array('sample' => 'alex', 'subject' => 's3', 'confidence' => '3065.38757'),
array('sample' => 'ali', 'subject' => 's3', 'confidence' => '2640.15458'),
array('sample' => 'shayan', 'subject' => 's3', 'confidence' => '2057.34011'),
array('sample' => 's1', 'subject' => 's3', 'confidence' => '1391.99415'),
array('sample' => 's2', 'subject' => 's3', 'confidence' => '2294.44428'),
array('sample' => 's3', 'subject' => 's3', 'confidence' => '1541.28356'),
array('sample' => 's4', 'subject' => 's3', 'confidence' => '2570.38641'),
array('sample' => 'agus', 'subject' => 's4', 'confidence' => '16.2224245'),
array('sample' => 'chapman', 'subject' => 's4', 'confidence' => '46.2447032'),
array('sample' => 'dayu', 'subject' => 's4', 'confidence' => '6.48832995'),
array('sample' => 'alex', 'subject' => 's4', 'confidence' => '31.9696273'),
array('sample' => 'ali', 'subject' => 's4', 'confidence' => '24.6307810'),
array('sample' => 'shayan', 'subject' => 's4', 'confidence' => '11.1537539'),
array('sample' => 's1', 'subject' => 's4', 'confidence' => '8.25046255'),
array('sample' => 's2', 'subject' => 's4', 'confidence' => '26.2144891'),
array('sample' => 's3', 'subject' => 's4', 'confidence' => '28.2781961'),
array('sample' => 's4', 'subject' => 's4', 'confidence' => '18.9397179'));
public static function GetConfidence($sample, $subject)
{
$confidence = "null";
foreach ($test_results as $test_result)
{
if(($test_result["sample"] == $sample) && ($test_result["subject"] == $subject))
{
$confidence = $test_result["confidence"];
}
}
return $confidence;
}
public static function AddPythonTests()
{
$o = new DB();
$db = $o->link();
$samples_array = ["agus_sample.jpg","chapman_sample.jpg","dayu_sample.jpg","alex_sample.jpg","ali_sample.jpg","shayan_sample.jpg","s1_sample.jpg","s2_sample.jpg","s3_sample.jpg","s4_sample.jpg"];
$subjects_array = ["chapman","dayu","alex","ali","shayan","s1","s2","s3","s4"];
$set_ids = [];
foreach ($subjects_array as $subject)
{
foreach ($samples_array as $sample)
{
$sql = "INSERT INTO \"tests\".\"Persons\" (\"PersonID\",\"InitialPicture\")
VALUES (DEFAULT, 'http://truly.am-demo.s3.amazonaws.com/".$sample."') RETURNING \"PersonID\"";
$newPersonID = $db->getOne($sql);
$imgs_array = [];
$name_aux = explode("_", $sample);
$name = $name_aux[0];
for ($i=1; $i < 6; $i++)
{
$imgs_array[] = "http://truly.am-demo.s3.amazonaws.com/".$subject."_".$i.".jpg";
}
$images_urls_str = implode("||", $imgs_array);
$sqlSets = "INSERT INTO \"tests\".\"VerificationSets\" (\"SetID\", \"Samples\", \"PersonID\",\"Date\")
VALUES (DEFAULT, '".$images_urls_str."', ".$newPersonID.", CURRENT_DATE) RETURNING \"SetID\"";
$newSetID = $db->getOne($sql);
$set_ids[] = array("SetID"=>$newSetID,
"sample"=>$name,
"subject"=>$subject
);
// $result = $db->Execute($sqlSets);
}
}
// Now that we have the SetID related with the sample and the subject, we can insert the test results
foreach ($set_ids as $set_id)
{
$confidence_aux = GetConfidence($set_id["sample"], $set_id["subject"]);
$confidence = explode(".", $confidence_aux);
$commit_version = "python-commit";
$confirmed_to_int = 0;
$algorithm = "pycv_v0.3";
$set_id = $set_id["SetID"];
$sql = "INSERT INTO \"tests\".\"TestResults\" (\"TestResultID\", \"Confidence\", \"CommitVersion\", \"IsTheSamePerson\", \"Algorithm\", \"SetID\")
VALUES (DEFAULT, ".$confidence[0].", '".$commit_version."', '".$confirmed_to_int."' ,'".$algorithm."', ".$set_id." )";
$result = $db->Execute($sql);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment