/* * { * "age": "25.5344", * "clean_exit": "false", * "enter_time": "2014-03-20T21:52:23", * "exit_time": "2014-03-20T21:59:09", * "gender": "1", * "id": "688", * "session_id": "5", * "time_periods": [ * { * "enter_time": "2014-03-20T21:52:23", * "exit_time": "2014-03-20T21:52:43" * }, * { * "enter_time": "2014-03-20T21:52:45", * "exit_time": "2014-03-20T21:52:55" * }, * { * "enter_time": "2014-03-20T21:53:18", * "exit_time": "2014-03-20T21:53:39" * }, * { * "enter_time": "2014-03-20T21:53:40", * "exit_time": "2014-03-20T21:54:01" * }, * { * "enter_time": "2014-03-20T21:54:13", * "exit_time": "2014-03-20T21:54:13" * }, * { * "enter_time": "2014-03-20T21:55:42", * "exit_time": "2014-03-20T21:56:14" * }, * { * "enter_time": "2014-03-20T21:59:02", * "exit_time": "2014-03-20T21:59:09" * } * ] * }, * * "age": "39.5744680851064", * "age_confidence": "0.480845452551689", * "gender": "-1", * "gender_confidence": "0.936170212765957", * */ public static FacesHistoricRec JsonToFacesHistoricRec(string txt) { try { var jFacesRec = JObject.Parse(txt); var rec = new FacesHistoricRec(); rec.faces = new List <FaceHistoricRec>(); foreach (var jfaces in jFacesRec["objects"]) { // load a specific person's record var face = new FaceHistoricRec(); face.id = StringToInt((string)jfaces["id"]); face.sessionId = StringToInt((string)jfaces["session_id"]); face.cleanExit = StringToBool((string)jfaces["clean_exit"]); face.age = (int)StringToFloat((string)jfaces["age"]); face.ageConfidence = (double)StringToFloat((string)jfaces["age_confidence"]); face.gender = StringToGender((string)jfaces["gender"]); face.genderConfidence = (double)StringToFloat((string)jfaces["gender_confidence"]); face.enterTime = StringToUtc((string)jfaces["enter_time"]).ToLocalTime(); face.exitTime = StringToUtc((string)jfaces["exit_time"]).ToLocalTime(); // load a person's time periods face.TimePeriods = new List <TimePeriod>(); foreach (var jperiod in jfaces["time_periods"]) { if (jperiod != null) { var period = new TimePeriod(); period.enterTime = StringToUtc((string)jperiod["enter_time"]).ToLocalTime(); period.exitTime = StringToUtc((string)jperiod["exit_time"]).ToLocalTime(); face.TimePeriods.Add(period); } } rec.faces.Add(face); } return(rec); } catch (Exception ex) { var newEx = new Exception("Invalid JSON data format returned for 'State'.", ex); throw newEx; } }
public HttpStatusCode GetFaces(DateTime start, DateTime end, out FacesHistoricRec faces) { ValidateIsBound(); var client = new LookRestClient(_device, _port, _username, _password); string body = null; var responseCode = client.GetFaces(start, end, out body); Trace.TraceInformation("\nRaw JSON data: {0}", body); if (responseCode == HttpStatusCode.OK) { faces = JsonHelper.JsonToFacesHistoricRec(body); } else { faces = null; } return(responseCode); }