/// <summary>
        /// Generates the age distr.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="companies">The companies.</param>
        /// <returns>List&lt;AgeDistribution&gt;.</returns>
        public List <AgeDistribution> GenerateAgeDistr(DateTime start, DateTime end, IEnumerable <string> companies)
        {
            start = new DateTime(start.Year, start.Month, start.Day);
            end   = new DateTime(end.Year, end.Month, end.Day);
            var result = new List <AgeDistribution>();

            using (var context = this.GetContext())
            {
                foreach (var company in companies)
                {
                    var ages = new AgeDistribution();
                    ages.Name = company;
                    var filter  = this.keywordManager.GetFilters(company);
                    var pattern = this.indexHelper.BuildPatternFromFilter(filter);

                    var tableName = TableNameHelper.GetNewsStreamTableName(this.currentClientUser.GetProfile().Postfix);
                    try
                    {
                        var cluster =
                            context.Database.SqlQuery <string>(
                                $@"select ClusterId0 from {tableName} 
                           where Contains(keywords, {{0}})",
                                pattern).ToList();
                    }catch (Exception e) { continue; }
                    var clusters =
                        context.Database.SqlQuery <string>(
                            $@"select ClusterId0 from {tableName} 
                           where Contains(keywords, {{0}})",
                            pattern).ToList();
                    var idList = clusters.ToList();

                    var vs = from vi in context.LocationAndUserDemo
                             where vi.Date >= start && vi.Date <= end && idList.Contains(vi.ClusterId0)
                             group vi by vi.AgeGroup
                             into s
                             select new { key = s.Key, value = s.Sum(x => x.QueryViewCount) };

                    var visitCount = vs.ToDictionary(i => i.key);
                    foreach (var item in visitCount)
                    {
                        var detail = new AgeDetail {
                            Name = item.Key, Value = (int)item.Value.value
                        };
                        ages.Details.Add(detail);
                    }

                    result.Add(ages);
                }
            }

            return(result);
        }
        private void UpdateAnalysisSummary()
        {
            if (frameAnalysis.DetectedFaces != null)
            {
                foreach (var face in frameAnalysis.DetectedFaces)
                {
                    frameAnalysis.Summary.TotalDetectedFaces++;
                    AgeDistribution genderBasedAgeDistribution = null;
                    if (face.FaceAttributes.Gender == Gender.Male)
                    {
                        frameAnalysis.Summary.TotalMales++;
                        genderBasedAgeDistribution = frameAnalysis.Summary.AgeGenderDistribution.MaleDistribution;
                    }
                    else
                    {
                        frameAnalysis.Summary.TotalFemales++;
                        genderBasedAgeDistribution = frameAnalysis.Summary.AgeGenderDistribution.FemaleDistribution;
                    }

                    if (face.FaceAttributes.Age < 16)
                    {
                        genderBasedAgeDistribution.Age0To15++;
                    }
                    else if (face.FaceAttributes.Age < 20)
                    {
                        genderBasedAgeDistribution.Age16To19++;
                    }
                    else if (face.FaceAttributes.Age < 30)
                    {
                        genderBasedAgeDistribution.Age20s++;
                    }
                    else if (face.FaceAttributes.Age < 40)
                    {
                        genderBasedAgeDistribution.Age30s++;
                    }
                    else if (face.FaceAttributes.Age < 50)
                    {
                        genderBasedAgeDistribution.Age40s++;
                    }
                    else if (face.FaceAttributes.Age < 60)
                    {
                        genderBasedAgeDistribution.Age50s++;
                    }
                    else
                    {
                        genderBasedAgeDistribution.Age60sAndOlder++;
                    }
                }
            }
        }
Example #3
0
        public void UpdateVisitorDemographics(SimilarFaceMatch item)
        {
            AgeDistribution genderBasedAgeDistribution = null;

            if (item.Face.FaceAttributes.Gender == Gender.Male)
            {
                Demographics.TotalMales++;
                genderBasedAgeDistribution = Demographics.AgeGenderDistribution.MaleDistribution;
            }
            else
            {
                Demographics.TotalFemales++;
                genderBasedAgeDistribution = Demographics.AgeGenderDistribution.FemaleDistribution;
            }

            if (item.Face.FaceAttributes.Age < 16)
            {
                genderBasedAgeDistribution.Age0To15++;
            }
            else if (item.Face.FaceAttributes.Age < 20)
            {
                genderBasedAgeDistribution.Age16To19++;
            }
            else if (item.Face.FaceAttributes.Age < 30)
            {
                genderBasedAgeDistribution.Age20s++;
            }
            else if (item.Face.FaceAttributes.Age < 40)
            {
                genderBasedAgeDistribution.Age30s++;
            }
            else if (item.Face.FaceAttributes.Age < 50)
            {
                genderBasedAgeDistribution.Age40s++;
            }
            else if (item.Face.FaceAttributes.Age < 60)
            {
                genderBasedAgeDistribution.Age50s++;
            }
            else
            {
                genderBasedAgeDistribution.Age60sAndOlder++;
            }

            //updating emotions as well:
            UpdateVisitorEmotions(item);
        }
Example #4
0
        private void UpdateAgeDistribution(Face face)
        {
            AgeDistribution genderBasedAgeDistribution = null;

            if (string.Compare(face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.demographics.OverallMaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
            }
            else
            {
                this.demographics.OverallFemaleCount++;
                genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
            }

            if (face.FaceAttributes.Age < 16)
            {
                genderBasedAgeDistribution.Age0To15++;
            }
            else if (face.FaceAttributes.Age < 20)
            {
                genderBasedAgeDistribution.Age16To19++;
            }
            else if (face.FaceAttributes.Age < 30)
            {
                genderBasedAgeDistribution.Age20s++;
            }
            else if (face.FaceAttributes.Age < 40)
            {
                genderBasedAgeDistribution.Age30s++;
            }
            else if (face.FaceAttributes.Age < 50)
            {
                genderBasedAgeDistribution.Age40s++;
            }
            else
            {
                genderBasedAgeDistribution.Age50sAndOlder++;
            }
        }
Example #5
0
        public string getCustomerAgeDistribution()
        {
            var groups = new List <AgeDistribution>();

            var db = new DBConnector(new Settings().warehousedb, "");

            var sql = " SELECT (select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup='0-18') `0-18`," +
                      "(select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup = '19-25') `19 - 25`," +
                      "(select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup = '26-35') `26 - 35`," +
                      "(select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup = '36-50') `36 - 50`," +
                      "(select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup = '51-64') `51 - 64`," +
                      "(select count(customerId) from inlaksbiwarehouse.customerdim where AgeGroup = '65+') `65 +`";

            var result = db.getDataSet(sql);

            for (int i = 0; i < result.Columns.Count; i++)
            {
                var group = new AgeDistribution();
                group.AgeGroup = result.Columns[i].ColumnName;
                group.Count    = result.Rows[0][i].toInt();
            }

            return(JsonConvert.SerializeObject(groups));
        }
Example #6
0
    // ---- Age ----
    public void LoadAgeStructure()
    {
        ageDistributions = new List <AgeDistribution>();
        string[] dataRows = DataLoadingHelpers.GetDataRows("Age/data");

        for (int i = 1; i < dataRows.Length - 1; i++)
        {
            string[]        row          = dataRows[i].Split(new char[] { ';' });
            AgeDistribution distribution = new AgeDistribution
            {
                ages     = new List <int>(),
                district = (Districts)(i - 1)
            };

            for (int age = 2; age < row.Length - 1; age++)
            {
                //Debug.Log(row[age]);
                int.TryParse(row[age], out int results);
                distribution.ages.Add(results);
            }

            ageDistributions.Add(distribution);
        }
    }