Example #1
0
 /// <summary>
 /// Initializes a DemographicAgeVerifier object and loads up the condition syntax
 /// and demographic keywords used in OxigenII.
 /// </summary>
 /// <param name="demographicData">Single or mutliple users' demographic data</param>
 public DemographicRangeVerifier(DemographicData demographicData)
 {
     _htDemographicQuestions = GetDemographicQuestions();
     _comparisonOperators    = GetComparisonOperators();
     _genders         = GetGenders();
     _demographicData = demographicData;
 }
Example #2
0
        private void RaiseDemographicsEvent(DemographicData payload)
        {
            var handler = this.DemographicsReceived;

            if (handler != null && payload != null)
            {
                handler(this, payload);
            }
        }
Example #3
0
        public void IsAssetDemoSyntaxPlayableTest()
        {
            DemographicData          demographicData = null;
            DemographicRangeVerifier target          = new DemographicRangeVerifier(demographicData);

            string[] inputConditionCollection = null;
            bool     expected = false;
            bool     actual;

            actual = target.IsAssetDemoSyntaxPlayable(inputConditionCollection);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #4
0
        [DynamicContent(MaxAgeInSeconds = 86400)] // 1 day
        public ActionResult DemographicData(string id)
        {
            DemographicData demographicData = (new DAService("Oxigen")).GetUserDemographicData(id);

            if (demographicData.Gender == null)
            {
                return(HttpNotFound());
            }

            byte[] demographicDataInBytes = Serializer.SerializeClearToByteArray(demographicData);
            var    fileContentResult      = new FileContentResult(demographicDataInBytes, System.Net.Mime.MediaTypeNames.Application.Octet);

            fileContentResult.FileDownloadName = "ss_demo_data.dat";
            return(fileContentResult);
        }
Example #5
0
 public IActionResult UpdateDemographicData(string userName, DemographicData demographicData)
 {
     try
     {
         ResultModel res = new ResultModel();
         if (demographicData == null)
         {
             return(BadRequest(new Exception("Unable to fetch record")));
         }
         else
         {
             res = _patientRepository.AddPatientDemographicData(userName, demographicData);
             return(Ok(res));
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Example #6
0
        public QuestionnaireFormCollectionParser(FormCollection formCollection)
        {
            QuestionAnswerMapping = new Dictionary <int, int>();
            DemographicData       = new DemographicDataContainer();
            foreach (string _formData in formCollection.AllKeys)
            {
                try
                {
                    int questionId = int.Parse(_formData);
                    int answerId   = int.Parse(formCollection[_formData]);
                    QuestionAnswerMapping.Add(questionId, answerId);
                }
                catch
                {
                    string value = formCollection[_formData];
                    switch (_formData)
                    {
                    case "DemographicData.SizeOfFacility":
                        DemographicData.SizeOfFacility =
                            EnumHelper.ParseEnum <FacilitySize?>(value);
                        break;

                    case "DemographicData.IndustrialClassification":
                        DemographicData.IndustrialClassification =
                            EnumHelper.ParseEnum <IndustrialClassification?>(value);
                        break;

                    case "DemographicData.AnotherProductClassification":
                        DemographicData.AnotherProductClassification =
                            EnumHelper.ParseEnum <AnotherProductClassification?>(value);
                        break;

                    case "DemographicData.AdditionalProductClassification":
                        DemographicData.AdditionalProductClassification =
                            EnumHelper.ParseEnum <AdditionalProductClassification?>(value);
                        break;
                    }
                }
            }
        }
Example #7
0
        public IActionResult GetDemographicData(string userName)
        {
            DemographicData data = new DemographicData();

            try
            {
                ResultModel res = new ResultModel();
                if (userName == null)
                {
                    return(BadRequest(new Exception("Unable to fetch record")));
                }
                else
                {
                    data = _patientRepository.GetDemographicById(userName);
                    return(Ok(data));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Example #8
0
        public void IsAssetDemoSyntaxPlayableIndividualLineTestSuccessfulConditionsInclude()
        {
            DemographicData demographicData = new DemographicData();

            demographicData.SocioEconomicgroup = new string[] { "a1", "a2" };
            demographicData.MaxAge             = 35;
            demographicData.MinAge             = 30;
            demographicData.GeoDefinition      = "0.1.2";
            demographicData.Gender             = new string[] { "male" };

            DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData);

            PrivateObject demographicRangeVerifierPrivate = new PrivateObject(demographicRangeVerifier);
            DemographicRangeVerifier_Accessor target      = new DemographicRangeVerifier_Accessor(demographicRangeVerifierPrivate);
            string ie = "age=34 and gender=male,female and socioeconomicgroup=a3,a2";

            bool expected = true;
            bool actual;

            actual = target.IsAssetDemoSyntaxPlayableIndividualLine(ie);
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void IsAssetPlayableIndividualLineTestLeadingTrailingConjunction()
        {
            DemographicData          demographicData          = null;
            DemographicRangeVerifier demographicRangeVerifier = null;

            demographicData = new DemographicData();

            demographicData.SocioEconomicgroup = new string[] { "a1", "a2" };
            demographicData.MaxAge             = 30;
            demographicData.MinAge             = 20;
            demographicData.GeoDefinition      = "0.1.2";
            demographicData.Gender             = new string[] { "Male" };

            demographicRangeVerifier = new DemographicRangeVerifier(demographicData);

            PrivateObject demographicRangeVerifierPrivate = new PrivateObject(demographicRangeVerifier);
            DemographicRangeVerifier_Accessor target      = new DemographicRangeVerifier_Accessor(demographicRangeVerifierPrivate);
            bool expected = false;
            bool actual;

            actual = target.IsAssetDemoSyntaxPlayableIndividualLine("age=20 and gender=male,female and socioeconomicgroup=a3,a2");
            Assert.AreEqual(expected, actual, "Verify the correctness of this test method.");
        }
Example #10
0
        private void btnClick_Click(object sender, EventArgs e)
        {
            //UserDataMarshallerClient client = new UserDataMarshallerClient();
            //client.Endpoint.Address = new EndpointAddress(@"http://relay-logs-a-1.obs-group.co.uk:81/Userdatamarshaller.svc");

            //DateTimeErrorWrapper dt = client.GetCurrentServerTime("password");

            //client.Dispose();

            try
            {
                DAClient client = new DAClient();

                DemographicData dg = client.GetUserDemographicData("31350825-4D31-48E3-8AFE-0F32C1D53096_A");

                client.Dispose();

                MessageBox.Show(dg.SocioEconomicgroup[0]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #11
0
        public void IsAssetDemoSyntaxPlayableTestSuccessfulConditionsExcludeIncludeSameMet()
        {
            DemographicData demographicData = new DemographicData();

            demographicData.SocioEconomicgroup = new string[] { "a1", "a2" };
            demographicData.MaxAge             = 35;
            demographicData.MinAge             = 30;
            demographicData.GeoDefinition      = "0.1.2";
            demographicData.Gender             = new string[] { "male" };

            DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData);

            string[] inputConditionCollection = new string[3];

            inputConditionCollection[0] = "age > 30 and gender=male and socioeconomicgroup=a2 and geo=0.1"; // will be met and excluded
            inputConditionCollection[1] = "age > 30 and gender=male and socioeconomicgroup=a2 and geo=0.1"; // will be met and excluded
            inputConditionCollection[2] = "age > 35 and gender=male and socioeconomicgroup=a2 and geo=0.3"; // will be not met and included

            bool expected = true;
            bool actual;

            actual = demographicRangeVerifier.IsAssetDemoSyntaxPlayable(inputConditionCollection);
            Assert.AreEqual(expected, actual, "Verify the correctness of this test method.");
        }
 private void RaiseDemographicsEvent(DemographicData payload)
 {
     var handler = this.DemographicsReceived;
     if (handler != null && payload != null)
         handler(this, payload);
 }
Example #13
0
        private async void ConnectionCallback(IAsyncResult asyncResult)
        {
            try
            {
                using (var pipeServer = asyncResult.AsyncState as NamedPipeServerStream)        // get the pipeserver
                {
                    if (pipeServer != null)
                    {
                        pipeServer.EndWaitForConnection(asyncResult);       // finish connection

                        byte[] buffer = new byte[16 * 1024];
                        using (MemoryStream memoryStream = new MemoryStream())  // create mem stream to read in bytes from pipe stream
                        {
                            int read;
                            while ((read = await pipeServer.ReadAsync(buffer, 0, buffer.Length)) > 0) // read to the end of the stream
                            {
                                memoryStream.Write(buffer, 0, read);                                  // write the bytes to memory
                            }

                            var json     = GetString(memoryStream.ToArray());                                            // convert bytes to string
                            var msg      = Newtonsoft.Json.JsonConvert.DeserializeObject <KioskMessage <object> >(json); // deserialize to message with object payload - payload will be a json string when <object> is used as generic type
                            var assembly = typeof(KioskMessage <object>).Assembly;                                       // find the assembly where are payload types can be found
                            var dataType = assembly.GetType(msg.DataType);                                               // get the type of the payload
                            var payload  = Newtonsoft.Json.JsonConvert.DeserializeObject(msg.Data.ToString(), dataType); // deserialize the payload json to the correct type

                            switch (dataType.FullName)                                                                   // brittle switch statements based on type string - better way?
                            {
                            case "KinectPOC.Common.Messages.Demographics":

                                DemographicData demographics = (DemographicData)payload;

                                RaiseDemographicsEvent(demographics);

                                UserExperienceContext uec = new UserExperienceContext();
                                uec.Age    = ((DemographicData)payload).Age;
                                uec.Gender = ((DemographicData)payload).Gender;
                                uec.FaceID = ((DemographicData)payload).FaceID;

                                uec.InteractionCount = 1;

                                if (demographics.FaceMatch)
                                {
                                    //Find out if we've already seen this person
                                    var orginalUser = (from users in _userExperiences where users.FaceID == demographics.FaceID select users).FirstOrDefault();

                                    if (orginalUser == null)
                                    {
                                        uec.TrackingId = demographics.TrackingId;
                                        _userExperiences.Add(uec);
                                    }
                                    else
                                    {
                                        orginalUser.TrackingId = demographics.TrackingId;
                                        orginalUser.InteractionCount++;
                                    }
                                }
                                else
                                {
                                    uec.TrackingId = demographics.TrackingId;
                                    _userExperiences.Add(uec);
                                }



                                break;
                            }
                        }

                        pipeServer.Close();
                    }
                }

                var newServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
                newServer.BeginWaitForConnection(new AsyncCallback(ConnectionCallback), newServer);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #14
0
        /// <summary>
        /// Creates the playlist for the user
        /// </summary>
        /// <param name="channelDataPath">Directory on the end user's computer where channel content files reside</param>
        /// <param name="advertListPath">Fully qualified path of the advert list file on the end user's computer</param>
        /// <param name="demographicDataPath">Fully qualified path of the demographic data path on the end user's computer</param>
        /// <param name="playlistDataPath">Fully qualified path on the end user's computer to save the playlist to</param>
        /// <param name="password">Encryption password</param>
        /// <param name="channelSubscriptions">ChannelSubscriptions object with the user's channel subscriptions</param>
        /// <param name="logger">Logger to log debug/error messages</param>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when an error occurs during serialization/deserializaton</exception>
        /// <exception cref="InvalidOperationException">Thrown when file to be serialized don't match the deserializer's expected type</exception>
        /// <exception cref="DirectoryNotFoundException">thrown when directory to save or load a file from is not found</exception>
        /// <exception cref="FileNotFoundException">thrown when a file is not found</exception>
        /// <exception cref="CryptographicException">thrown when a serialized file is corrupted</exception>
        public static Playlist CreatePlaylist(string channelDataPath,
                                              string advertListPath,
                                              string demographicDataPath,
                                              string playlistDataPath,
                                              string password,
                                              float defaultDisplayDuration,
                                              ChannelSubscriptions channelSubscriptions,
                                              Logger logger)
        {
            Playlist playlist = new Playlist();

            // holds the channels to which the user is subscribed
            ChannelData channelData = new ChannelData();

            // check if channel data directory exists!
            if (!Directory.Exists(channelDataPath))
            {
                return(null);
            }

            string[] fileEntries = Directory.GetFiles(channelDataPath, "*.dat");

            if (channelSubscriptions.SubscriptionSet.Count == 0 || fileEntries.Length == 0)
            {
                return(playlist);
            }

            foreach (string file in fileEntries)
            {
                channelData.Channels.Add((Channel)Serializer.Deserialize(typeof(Channel), file, "password"));
            }

            if (!File.Exists(demographicDataPath))
            {
                return(null);
            }

            DateTime now = DateTime.Now;

            DemographicData demographicData = (DemographicData)Serializer.Deserialize(typeof(DemographicData), demographicDataPath, password);

            DemographicRangeVerifier demographicRangeVerifier = new DemographicRangeVerifier(demographicData);

            GetNonAdvertisingPlaylist(channelData,
                                      password,
                                      playlist,
                                      demographicRangeVerifier,
                                      channelSubscriptions,
                                      now,
                                      defaultDisplayDuration,
                                      logger);

            // advertising playlist
            GetAdvertisingPlaylist(advertListPath,
                                   demographicDataPath,
                                   demographicRangeVerifier,
                                   password,
                                   playlist,
                                   channelData,
                                   channelSubscriptions,
                                   now,
                                   logger);

            Serializer.Serialize(playlist, playlistDataPath, password);

            return(playlist);
        }
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (type == typeof(Demographic <Gender>))
            {
                var obj = new Demographic <Gender>();
                if (dictionary.ContainsKey("data"))
                {
                    obj.Data = serializer.ConvertToType <List <DemographicData <Gender> > >(dictionary["data"]);
                }

                return(obj);
            }
            else if (type == typeof(Demographic <Country>))
            {
                var obj = new Demographic <Country>();
                if (dictionary.ContainsKey("data"))
                {
                    obj.Data = serializer.ConvertToType <List <DemographicData <Country> > >(dictionary["data"]);
                }

                return(obj);
            }
            else if (type == typeof(Demographic <Locale>))
            {
                var obj = new Demographic <Locale>();
                if (dictionary.ContainsKey("data"))
                {
                    obj.Data = serializer.ConvertToType <List <DemographicData <Locale> > >(dictionary["data"]);
                }

                return(obj);
            }
            else if (type == typeof(DemographicData <Gender>))
            {
                var obj = new DemographicData <Gender>();
                if (dictionary.ContainsKey("id"))
                {
                    obj.id = serializer.ConvertToType <string>(dictionary["id"]);
                }

                if (dictionary.ContainsKey("name"))
                {
                    obj.Name = serializer.ConvertToType <string>(dictionary["name"]);
                }

                if (dictionary.ContainsKey("values"))
                {
                    obj.Days = serializer.ConvertToType <List <Daily <Gender> > >(dictionary["values"]);
                }

                return(obj);
            }
            else if (type == typeof(DemographicData <Country>))
            {
                var obj = new DemographicData <Country>();
                if (dictionary.ContainsKey("id"))
                {
                    obj.id = serializer.ConvertToType <string>(dictionary["id"]);
                }

                if (dictionary.ContainsKey("name"))
                {
                    obj.Name = serializer.ConvertToType <string>(dictionary["name"]);
                }

                if (dictionary.ContainsKey("values"))
                {
                    obj.Days = serializer.ConvertToType <List <Daily <Country> > >(dictionary["values"]);
                }

                return(obj);
            }
            else if (type == typeof(DemographicData <Locale>))
            {
                var obj = new DemographicData <Locale>();
                if (dictionary.ContainsKey("id"))
                {
                    obj.id = serializer.ConvertToType <string>(dictionary["id"]);
                }

                if (dictionary.ContainsKey("name"))
                {
                    obj.Name = serializer.ConvertToType <string>(dictionary["name"]);
                }

                if (dictionary.ContainsKey("values"))
                {
                    obj.Days = serializer.ConvertToType <List <Daily <Locale> > >(dictionary["values"]);
                }

                return(obj);
            }
            else if (type == typeof(Daily <Gender>))
            {
                var obj = new Daily <Gender>();
                if (dictionary.ContainsKey("end_time"))
                {
                    obj.End_Time = serializer.ConvertToType <string>(dictionary["end_time"]);
                }

                if (dictionary.ContainsKey("value"))
                {
                    obj.Gender = serializer.ConvertToType <Gender>(dictionary["value"]);
                }

                return(obj);
            }
            else if (type == typeof(Daily <Country>))
            {
                var obj = new Daily <Country>();
                if (dictionary.ContainsKey("end_time"))
                {
                    obj.End_Time = serializer.ConvertToType <string>(dictionary["end_time"]);
                }

                if (dictionary.ContainsKey("value"))
                {
                    obj.Country = serializer.ConvertToType <Country>(dictionary["value"]);
                }

                return(obj);
            }
            else if (type == typeof(Daily <Locale>))
            {
                var obj = new Daily <Locale>();
                if (dictionary.ContainsKey("end_time"))
                {
                    obj.End_Time = serializer.ConvertToType <string>(dictionary["end_time"]);
                }

                if (dictionary.ContainsKey("value"))
                {
                    obj.Locale = serializer.ConvertToType <Locale>(dictionary["value"]);
                }

                return(obj);
            }
            else if (type == typeof(Gender))
            {
                var obj = new Gender();

                obj.M_25to34 = SetValue(serializer, dictionary, "M.25-34");
                obj.M_18to24 = SetValue(serializer, dictionary, "M.18-24");
                obj.M_45to54 = SetValue(serializer, dictionary, "M.45-54");
                obj.F_25to34 = SetValue(serializer, dictionary, "F.25-34");
                obj.F_35to44 = SetValue(serializer, dictionary, "F.35-44");
                obj.F_45to54 = SetValue(serializer, dictionary, "F.45-54");
                obj.F_18to24 = SetValue(serializer, dictionary, "F.18-24");
                obj.M_55to64 = SetValue(serializer, dictionary, "M.55-64");
                obj.M_13to17 = SetValue(serializer, dictionary, "M.13-17");
                obj.F_55to64 = SetValue(serializer, dictionary, "F.55-64");
                obj.M_65to   = SetValue(serializer, dictionary, "M.65+");
                obj.F_13to17 = SetValue(serializer, dictionary, "F.13-17");
                obj.F_65to   = SetValue(serializer, dictionary, "F.65+");
                obj.U_25to34 = SetValue(serializer, dictionary, "U.25-34");
                obj.U_35to44 = SetValue(serializer, dictionary, "U.35-44");
                obj.U_45to54 = SetValue(serializer, dictionary, "U.45-54");
                obj.U_18to24 = SetValue(serializer, dictionary, "U.18-24");
                obj.U_55to64 = SetValue(serializer, dictionary, "U.55-64");
                obj.U_65to   = SetValue(serializer, dictionary, "U.65to+");

                return(obj);
            }

            return(null);
        }
Example #16
0
        public static void buildCSV(StreamWriter csv, Guid orgId, Guid projId, Guid?locId, DateTime?startDate, DateTime?endDate)
        {
            var repo      = new ReportsRepository();
            var riskMap   = repo.projectRiskMap(orgId, projId);
            var projectQs = repo.projectQuestions(projId);

            csv.WriteLine("Project," + repo.projectName(projId));
            csv.WriteLine("Location," + repo.locationName(locId));
            csv.WriteLine("Start Date," + Reports.formatDate(startDate));
            csv.WriteLine("End Date," + Reports.formatDate(endDate));


            csv.Write("Name,");
            csv.Write("Ref Id,");
            csv.Write("Post Code,");
            csv.Write("In area of deprivation,");
            csv.Write("Referred by,");
            csv.Write("Project,");
            csv.Write("Location,");
            csv.Write("Date of birth,");
            csv.Write("Disability,");
            csv.Write("Disability Type,");
            csv.Write("Employment Status,");
            csv.Write("Ethnic Origin,");
            csv.Write("Gender,");
            csv.Write("Household Income,");
            csv.Write("Household Type,");
            csv.Write("Housing Type,");
            csv.Write("Marital Status,");
            csv.Write("Registration Date,");
            foreach (var q in projectQs)
            {
                csv.Write(q.Question + ",");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Initial " + t + " score,");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Highest " + t + " score,");
            }
            foreach (var t in riskMap.AllThemes())
            {
                csv.Write("Current " + t + " score,");
            }
            csv.Write("Discharge Date");
            csv.WriteLine();

            const int pageSize = 200;
            int       page     = 0;

            while (true)
            {
                var clientDatas = repo.findClients(projId, locId).
                                  OrderBy(c => c.Id).
                                  Skip(page * pageSize).
                                  Take(pageSize).
                                  Include(c => c.Address).
                                  Include(c => c.Demographics).
                                  Include(c => c.ProjectAnswers).ToList();
                if (clientDatas.Count == 0)
                {
                    break;
                }

                var clients = new List <Client>();
                foreach (var cd in clientDatas)
                {
                    if (!Reports.activeBetweenDates(cd, startDate, endDate))
                    {
                        continue;
                    }
                    clients.Add(new Client(cd, riskMap, projectQs, null));
                } // foreach

                foreach (var client in clients)
                {
                    try {
                        var riskAssessment = client.CurrentRiskAssessment;

                        csv.Write(client.Name + ",");
                        csv.Write(client.ReferenceId + ",");
                        csv.Write(client.Address.PostCode + ",");
                        csv.Write(client.Address.IsInDeprivedArea + ",");
                        csv.Write(referredBy(client.referredBy()) + ",");
                        csv.Write(repo.projectName(client.ProjectId) + ",");
                        csv.Write(repo.locationName(client.LocationId) + ",");

                        var demographics = client.Demographics;
                        if (demographics == null)
                        {
                            demographics = new DemographicData();
                        }

                        csv.Write(Reports.formatDate(demographics.Dob) + ",");
                        csv.Write(demographics.Disability + ",");
                        csv.Write(demographics.DisabilityType + ",");
                        csv.Write(demographics.EmploymentStatus + ",");
                        csv.Write(demographics.EthnicOrigin + ",");
                        csv.Write(demographics.Gender + ",");
                        csv.Write(demographics.HouseholdIncome + ",");
                        csv.Write(demographics.HouseholdType + ",");
                        csv.Write(demographics.HousingType + ",");
                        csv.Write(demographics.MaritalStatus + ",");
                        csv.Write(Reports.formatDate(client.registeredOn()) + ",");
                        foreach (var pq in client.Questions)
                        {
                            csv.Write(pq.Answer + ",");
                        }

                        var ra = client.CurrentRiskAssessment;
                        // Initial scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.InitialScore + ",");
                        }
                        // High scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.HighScore + ",");
                        }
                        // Current scores
                        foreach (var t in ra.ThemeAssessments)
                        {
                            csv.Write(t.Score + ",");
                        }

                        // Discharge Date
                        csv.Write(Reports.formatDate(client.Discharged));
                    } catch (Exception e) {
                        csv.Write("Error exporting - " + e.Message);
                    }
                    csv.WriteLine();
                    csv.Flush();
                } // foreach Client
                ++page;
            }     // while(true)

            csv.Close();
        }