From 19fac4d8108dc8a67bb5c18dd860cda86442bf28 Mon Sep 17 00:00:00 2001 From: uppuv Date: Tue, 7 Nov 2023 17:04:19 -0500 Subject: [PATCH] completed heatmap api changes for location and response api --- .../Db/Location.cs | 4 ++ .../Models/Location.cs | 4 ++ .../Providers/LocationsProvider.cs | 19 +++++-- .../Models/Location.cs | 4 ++ .../Providers/SurveyResponsesProvider.cs | 52 +++++++++++++------ 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/Location.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/Location.cs index 78e1921..8b91a26 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/Location.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/Location.cs @@ -21,6 +21,10 @@ namespace DamageAssesment.Api.Locations.Db [StringLength(2)] public string SchoolType { get; set; } + public int? DataValue { get; set; } + public int? Enrollment { get; set; } + public double? Longitute { get; set; } + public double? Latitude { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Models/Location.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Models/Location.cs index eafbea6..8f2e8b8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Models/Location.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Models/Location.cs @@ -11,5 +11,9 @@ namespace DamageAssesment.Api.Locations.Models public string Name { get; set; } public string MaintenanceCenter { get; set; } public string SchoolType { get; set; } + public int? DataValue { get; set; } + public int? Enrollment { get; set; } + public double? Longitute { get; set; } + public double? Latitude { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs index 198a765..9c26d08 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs @@ -17,7 +17,7 @@ namespace DamageAssesment.Api.Locations.Providers this.locationDbContext = locationDbContext; this.logger = logger; this.mapper = mapper; - // SeedData(); + // SeedData(); } public async Task<(bool IsSuccess, IEnumerable Locations, string ErrorMessage)> GetLocationsAsync() @@ -28,6 +28,8 @@ namespace DamageAssesment.Api.Locations.Providers var locations = await locationDbContext.Locations.AsNoTracking().ToListAsync(); if (locations != null) { + int maxenrollment = (int)locations.Max(a => a.Enrollment); + foreach (Db.Location item in locations) { item.DataValue = GetHeatmapdata(item.Enrollment, maxenrollment); } logger?.LogInformation($"{locations.Count} Locations(s) found"); var result = mapper.Map, IEnumerable>(locations); return (true, result, null); @@ -46,9 +48,12 @@ namespace DamageAssesment.Api.Locations.Providers try { logger?.LogInformation("Query Location"); + + int maxenrollment = (int)await locationDbContext.Locations.AsNoTracking().MaxAsync(a => a.Enrollment); var location = await locationDbContext.Locations.AsNoTracking().FirstOrDefaultAsync(q => q.Id == Id); if (location != null) - { + {if(maxenrollment>0) + location.DataValue = GetHeatmapdata(location.Enrollment, maxenrollment); logger?.LogInformation($"{location} found"); var result = mapper.Map(location); return (true, result, null); @@ -61,6 +66,10 @@ namespace DamageAssesment.Api.Locations.Providers return (false, null, ex.Message); } } + private int GetHeatmapdata(int? enrollment,int maxenrollment) + { + return (enrollment != null ? enrollment.Value : 0) * 100 / maxenrollment; + } public async Task<(bool IsSuccess, Models.Location Location, string ErrorMessage)> PostLocationAsync(Models.Location location) { try @@ -139,9 +148,9 @@ namespace DamageAssesment.Api.Locations.Providers { if (!locationDbContext.Locations.Any()) { - locationDbContext.Locations.Add(new Db.Location() { LocationCode = "0091", RegionId = 5, Name = "BOB GRAHAM EDUCATION CENTER", MaintenanceCenter = "1", SchoolType = "K8" }); - locationDbContext.Locations.Add(new Db.Location() { LocationCode = "0092", RegionId = 1, Name = "NORMAN S. EDELCUP/SUNNY ISLES BEACH K-8", MaintenanceCenter = "1", SchoolType = "K8" }); - locationDbContext.Locations.Add(new Db.Location() { LocationCode = "7511", RegionId = 4, Name = "MIAMI SPRINGS SHS", MaintenanceCenter = "2", SchoolType = "S" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "0091", RegionId = 5, Name = "BOB GRAHAM EDUCATION CENTER", MaintenanceCenter = "1", SchoolType = "K8", DataValue = 25,Enrollment=780,Latitude= 25.83604,Longitute= -80.21618 }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "0092", RegionId = 1, Name = "NORMAN S. EDELCUP/SUNNY ISLES BEACH K-8", MaintenanceCenter = "1", SchoolType = "K8", DataValue = 46, Enrollment = 650, Latitude = 20.83604, Longitute = -40.21618 }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "7511", RegionId = 4, Name = "MIAMI SPRINGS SHS", MaintenanceCenter = "2", SchoolType = "S", DataValue = 12, Enrollment = 500, Latitude = 53.83604, Longitute = -60.21618 }); //locationDbContext.Locations.Add(new Db.Location() { Id = 3, LocationCode = "Loc3", RegionId = 3, Name = "BOB GRAHAM EDUCATION CENTER 3", MaintenanceCenter = "1", SchoolType = "US" }); //locationDbContext.Locations.Add(new Db.Location() { Id = 4, LocationCode = "Loc4", RegionId = 1, Name = "BOB GRAHAM EDUCATION CENTER 4", MaintenanceCenter = "1", SchoolType = "US" }); //locationDbContext.Locations.Add(new Db.Location() { Id = 5, LocationCode = "Loc5", RegionId = 2, Name = "BOB GRAHAM EDUCATION CENTER 5", MaintenanceCenter = "1", SchoolType = "US" }); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Models/Location.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Models/Location.cs index e217a7b..704e1b9 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Models/Location.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Models/Location.cs @@ -8,5 +8,9 @@ public string Name { get; set; } public string MaintenanceCenter { get; set; } public string SchoolType { get; set; } + public int? DataValue { get; set; } + public int? Enrollment { get; set; } + public double? Longitute { get; set; } + public double? Latitude { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs index d52d153..8dedee9 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs @@ -512,17 +512,19 @@ namespace DamageAssesment.Api.Responses.Providers var allQuestions = await questionServiceProvider.getQuestionsAsync(null); var questions = allQuestions.Where(s => s.SurveyId == surveyResponse.SurveyId); var attachments = await attachmentServiceProvider.getAttachmentsAsync(); - - var result = new - { + var Locations = await locationServiceProvider.getLocationsAsync(); + var location = Locations.Where(a => a.Id == surveyResponse.LocationId).FirstOrDefault(); + var result = new{ surveyResponse.Id, surveyResponse.SurveyId, surveyResponse.LocationId, surveyResponse.EmployeeId, surveyResponse.ClientDevice, surveyResponse.KeyAnswerResult, - surveyResponse.Longitute, - surveyResponse.Latitude, + DataValue=(location!=null?location.DataValue:0), + Enrollment= (location != null ? location.Enrollment : 0), + Longitute = (location != null ? location.Longitute : surveyResponse.Longitute), + Latitude=(location != null ? location.Latitude : surveyResponse.Latitude), Employee = employee, answers = from ans in answers select new @@ -566,6 +568,7 @@ namespace DamageAssesment.Api.Responses.Providers var answers = await answerServiceProvider.getAnswersAsync(); var questions = await questionServiceProvider.getQuestionsAsync(null); + var Locations = await locationServiceProvider.getLocationsAsync(); var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; //var surveyQuestions = await questionServiceProvider.getSurveyQuestionsAsync(surveyId); @@ -575,6 +578,7 @@ namespace DamageAssesment.Api.Responses.Providers if (employeeid == 0) { var result = from r in surveyResonses + join loc in Locations on r.LocationId equals loc.Id select new { r.Id, @@ -583,8 +587,10 @@ namespace DamageAssesment.Api.Responses.Providers r.EmployeeId, r.ClientDevice, r.KeyAnswerResult, - r.Longitute, - r.Latitude, + loc.DataValue, + loc.Enrollment, + loc.Longitute, + loc.Latitude, Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), answers = from ans in answers where ans.SurveyResponseId == r.Id @@ -609,6 +615,7 @@ namespace DamageAssesment.Api.Responses.Providers _employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber }; } var result = from r in surveyResonses + join loc in Locations on r.LocationId equals loc.Id select new { r.Id, @@ -617,8 +624,10 @@ namespace DamageAssesment.Api.Responses.Providers r.EmployeeId, r.ClientDevice, r.KeyAnswerResult, - r.Longitute, - r.Latitude, + loc.DataValue, + loc.Enrollment, + loc.Longitute, + loc.Latitude, Employee = _employee, answers = from ans in answers where ans.SurveyResponseId == r.Id @@ -674,7 +683,9 @@ namespace DamageAssesment.Api.Responses.Providers var questions = await questionServiceProvider.getQuestionsAsync(null); var attachments = await attachmentServiceProvider.getAttachmentsAsync(); + var Locations = await locationServiceProvider.getLocationsAsync(); var result = from r in surveyResonses + join loc in Locations on r.LocationId equals loc.Id select new { r.Id, @@ -683,8 +694,10 @@ namespace DamageAssesment.Api.Responses.Providers r.EmployeeId, r.ClientDevice, r.KeyAnswerResult, - r.Longitute, - r.Latitude, + loc.DataValue, + loc.Enrollment, + loc.Longitute, + loc.Latitude, Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), answers = from ans in answers where ans.SurveyResponseId == r.Id @@ -938,7 +951,9 @@ namespace DamageAssesment.Api.Responses.Providers var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; var attachments = await attachmentServiceProvider.getAttachmentsAsync(); + var Locations = await locationServiceProvider.getLocationsAsync(); var result = from r in surveyResonses + join loc in Locations on r.LocationId equals loc.Id select new { r.Id, @@ -947,8 +962,10 @@ namespace DamageAssesment.Api.Responses.Providers r.EmployeeId, r.ClientDevice, r.KeyAnswerResult, - r.Longitute, - r.Latitude, + loc.DataValue, + loc.Enrollment, + loc.Longitute, + loc.Latitude, Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), answers = from ans in answers where ans.SurveyResponseId == r.Id @@ -1004,8 +1021,9 @@ namespace DamageAssesment.Api.Responses.Providers // var employees = await employeeServiceProvider.getEmployeesAsync(); var answers = await answerServiceProvider.getAnswersAsync(); var attachments = await attachmentServiceProvider.getAttachmentsAsync(); - + var Locations = await locationServiceProvider.getLocationsAsync(); var result = from r in surveyResponses + join loc in Locations on r.LocationId equals loc.Id select new { r.Id, @@ -1014,8 +1032,10 @@ namespace DamageAssesment.Api.Responses.Providers r.EmployeeId, r.ClientDevice, r.KeyAnswerResult, - r.Longitute, - r.Latitude, + loc.DataValue, + loc.Enrollment, + loc.Longitute, + loc.Latitude, Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(), answers = from ans in answers where ans.SurveyResponseId == r.Id