From 481b7797a13152bd44c362246723f0832a7d9e7a Mon Sep 17 00:00:00 2001 From: Qaisyousuf Date: Thu, 28 Aug 2025 12:11:56 +0200 Subject: [PATCH] Add AI-powered basic analysis feature for processing survey results --- Services/Implemnetation/AiAnalysisService.cs | 51 +++ Services/Interaces/IAiAnalysisService.cs | 11 + Services/Services.csproj | 3 + .../Controllers/SurveyAnalysisController.cs | 54 ++- .../Views/SurveyAnalysis/AiAnalysis.cshtml | 71 ++++ .../Admin/Views/SurveyAnalysis/Index.cshtml | 1 + Web/Extesions/ServicesExtesions.cs | 7 + Web/Program.cs | 1 + et --hard HEAD~1 | 365 ++++++++++++++++++ 9 files changed, 563 insertions(+), 1 deletion(-) create mode 100644 Services/Implemnetation/AiAnalysisService.cs create mode 100644 Services/Interaces/IAiAnalysisService.cs create mode 100644 Web/Areas/Admin/Views/SurveyAnalysis/AiAnalysis.cshtml create mode 100644 et --hard HEAD~1 diff --git a/Services/Implemnetation/AiAnalysisService.cs b/Services/Implemnetation/AiAnalysisService.cs new file mode 100644 index 0000000..d4c0858 --- /dev/null +++ b/Services/Implemnetation/AiAnalysisService.cs @@ -0,0 +1,51 @@ +using Azure; +using Azure.AI.TextAnalytics; +using Microsoft.Extensions.Configuration; +using Services.Interaces; + +namespace Services.Implemnetation +{ + public class AiAnalysisService : IAiAnalysisService + { + private readonly TextAnalyticsClient _client; + + public AiAnalysisService(IConfiguration configuration) + { + var endpoint = configuration["AzureLanguageService:Endpoint"]; + var key = configuration["AzureLanguageService:Key"]; + + _client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(key)); + } + + public async Task AnalyzeSentimentAsync(string text) + { + var response = await _client.AnalyzeSentimentAsync(text); + return response.Value; + } + + public async Task GetRiskAssessmentAsync(string text) + { + var sentiment = await AnalyzeSentimentAsync(text); + + // Simple risk assessment logic + if (sentiment.Sentiment == TextSentiment.Negative && sentiment.ConfidenceScores.Negative > 0.8) + { + return "High Risk - Consider follow-up"; + } + else if (sentiment.Sentiment == TextSentiment.Negative) + { + return "Medium Risk - Monitor"; + } + else + { + return "Low Risk"; + } + } + + public async Task> ExtractKeyPhrasesAsync(string text) + { + var response = await _client.ExtractKeyPhrasesAsync(text); + return response.Value.ToList(); + } + } +} diff --git a/Services/Interaces/IAiAnalysisService.cs b/Services/Interaces/IAiAnalysisService.cs new file mode 100644 index 0000000..fd083ec --- /dev/null +++ b/Services/Interaces/IAiAnalysisService.cs @@ -0,0 +1,11 @@ +using Azure.AI.TextAnalytics; + +namespace Services.Interaces +{ + public interface IAiAnalysisService + { + Task AnalyzeSentimentAsync(string text); + Task GetRiskAssessmentAsync(string text); + Task> ExtractKeyPhrasesAsync(string text); + } +} diff --git a/Services/Services.csproj b/Services/Services.csproj index 7e048a3..9af6a3d 100644 --- a/Services/Services.csproj +++ b/Services/Services.csproj @@ -7,8 +7,11 @@ + + + diff --git a/Web/Areas/Admin/Controllers/SurveyAnalysisController.cs b/Web/Areas/Admin/Controllers/SurveyAnalysisController.cs index 9fdab2b..95a1596 100644 --- a/Web/Areas/Admin/Controllers/SurveyAnalysisController.cs +++ b/Web/Areas/Admin/Controllers/SurveyAnalysisController.cs @@ -7,6 +7,8 @@ using Web.ViewModel.QuestionnaireVM; using System.IO; using Microsoft.AspNetCore.Authorization; +using Services.Implemnetation; +using Services.Interaces; namespace Web.Areas.Admin.Controllers { @@ -15,10 +17,12 @@ namespace Web.Areas.Admin.Controllers public class SurveyAnalysisController : Controller { private readonly SurveyContext _context; + private readonly IAiAnalysisService _aiAnalysisService; - public SurveyAnalysisController(SurveyContext context) + public SurveyAnalysisController(SurveyContext context, IAiAnalysisService aiAnalysisService) { _context = context; + _aiAnalysisService = aiAnalysisService; } public IActionResult Index() { @@ -115,7 +119,55 @@ namespace Web.Areas.Admin.Controllers } + [HttpGet] + public async Task AiAnalysis(int id) + { + // Get survey responses for the questionnaire + var responses = await _context.Responses + .Where(r => r.QuestionnaireId == id) + .Include(r => r.ResponseDetails) + .ThenInclude(rd => rd.Question) + .Include(r => r.Questionnaire) + .ToListAsync(); + if (!responses.Any()) + { + return NotFound("No responses found for this questionnaire."); + } + + var analysisResults = new List(); + + foreach (var response in responses) + { + foreach (var detail in response.ResponseDetails) + { + if (!string.IsNullOrWhiteSpace(detail.TextResponse)) + { + // Analyze the text response with AI + var sentiment = await _aiAnalysisService.AnalyzeSentimentAsync(detail.TextResponse); + var riskAssessment = await _aiAnalysisService.GetRiskAssessmentAsync(detail.TextResponse); + var keyPhrases = await _aiAnalysisService.ExtractKeyPhrasesAsync(detail.TextResponse); + + analysisResults.Add(new + { + UserName = response.UserName, + UserEmail = response.UserEmail, + Question = detail.Question.Text, + Response = detail.TextResponse, + Sentiment = sentiment.Sentiment.ToString(), + PositiveScore = sentiment.ConfidenceScores.Positive, + NegativeScore = sentiment.ConfidenceScores.Negative, + NeutralScore = sentiment.ConfidenceScores.Neutral, + RiskAssessment = riskAssessment, + KeyPhrases = keyPhrases + }); + } + } + } + + ViewBag.QuestionnaireName = responses.First().Questionnaire.Title; + return View(analysisResults); + } } } diff --git a/Web/Areas/Admin/Views/SurveyAnalysis/AiAnalysis.cshtml b/Web/Areas/Admin/Views/SurveyAnalysis/AiAnalysis.cshtml new file mode 100644 index 0000000..6e55342 --- /dev/null +++ b/Web/Areas/Admin/Views/SurveyAnalysis/AiAnalysis.cshtml @@ -0,0 +1,71 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "AI Analysis Results"; +} + +
+
+
+

AI Analysis: @ViewBag.QuestionnaireName

+
+
+ + @if (Model.Any()) + { +
+ + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + + } + +
UserQuestionResponseSentimentRisk LevelKey PhrasesConfidence Scores
@item.UserName@item.Question@item.Response + + @item.Sentiment + + + + @item.RiskAssessment + + + @string.Join(", ", item.KeyPhrases) + + + Pos: @item.PositiveScore.ToString("F2")
+ Neg: @item.NegativeScore.ToString("F2")
+ Neu: @item.NeutralScore.ToString("F2") +
+
+
+ } + else + { +

No text responses found to analyze.

+ } +
+
+
\ No newline at end of file diff --git a/Web/Areas/Admin/Views/SurveyAnalysis/Index.cshtml b/Web/Areas/Admin/Views/SurveyAnalysis/Index.cshtml index 0e86f78..189b876 100644 --- a/Web/Areas/Admin/Views/SurveyAnalysis/Index.cshtml +++ b/Web/Areas/Admin/Views/SurveyAnalysis/Index.cshtml @@ -35,6 +35,7 @@ Analyzer + AI Analysis } diff --git a/Web/Extesions/ServicesExtesions.cs b/Web/Extesions/ServicesExtesions.cs index 1d48782..7afb040 100644 --- a/Web/Extesions/ServicesExtesions.cs +++ b/Web/Extesions/ServicesExtesions.cs @@ -87,6 +87,13 @@ namespace Web.Extesions public static void MailStatConfiguration(this IServiceCollection services) { services.AddTransient(); + + + } + + public static void ConfigureAIAnalysis(this IServiceCollection services) + { + services.AddScoped(); } //public static void MailConfiguration(this IServiceCollection services, IConfiguration configuration) diff --git a/Web/Program.cs b/Web/Program.cs index 6af26c2..1d27498 100644 --- a/Web/Program.cs +++ b/Web/Program.cs @@ -38,6 +38,7 @@ builder.Services.ConfigureDashboard(); builder.Services.UserResponseConfiguration(); builder.Services.ConfigureOpenAI(config); builder.Services.AddSignalR(); +builder.Services.ConfigureAIAnalysis(); diff --git a/et --hard HEAD~1 b/et --hard HEAD~1 new file mode 100644 index 0000000..c50047a --- /dev/null +++ b/et --hard HEAD~1 @@ -0,0 +1,365 @@ +commit 0792b1e1d5722dfb9e1bba65a0db15997a0c33df (HEAD -> main) +Author: Qaisyousuf +Date: Thu Aug 28 09:36:10 2025 +0200 + + Add AI-powered basic analysis feature for processing survey results + +commit cf77b41da7cdaec857095b267768e34b74844841 (origin/main) +Author: Qaisyousuf +Date: Tue Aug 26 13:45:33 2025 +0200 + + Add database backup + +commit 4019fc4a951599d7a4d96a3d2e1d37a7d8b9a144 +Author: Qaisyousuf +Date: Tue Aug 26 13:42:26 2025 +0200 + + Improve frontend design and layout + +commit 1b1a736f3f17af9cb700a8b0526bcd7ec1c34a41 +Author: Qaisyousuf +Date: Mon Aug 25 12:19:43 2025 +0200 + + Improve dashboard to display real data + +commit 43461bbb2bcac49f097023fff0d5c86c435fc6d9 +Author: Qaisyousuf +Date: Wed Aug 20 13:29:10 2025 +0200 + + Add questionnaire status management with draft, archive, and recover options + +commit b67eca07293ae7b2a67f7c6f720d7d28a83544f2 +Author: Qaisyousuf +Date: Fri Aug 15 17:26:46 2025 +0200 + + Improve overall questionnaire design and user response experience + +commit d9f9b600d7c4911abef12b917642c6f586c1e375 +Author: Qaisyousuf +Date: Thu Aug 14 15:07:48 2025 +0200 + + Add 'Other' option to questionnaire for custom user input + +commit 908e241fd8caeb70f840e70a61f3603526240a85 +Author: Qaisyousuf +Date: Wed Aug 13 17:03:21 2025 +0200 + + Improve questionnaire UI for better usability on smaller devices + +commit f6a03302fd7818623e69d24136c50883fc6219d7 +Author: Qaisyousuf +Date: Mon Aug 11 18:06:13 2025 +0200 + + Add backend condition logic for user questionnaire submission handling + +commit 2ce5b50c9702b0b2a3a6b366a8ebf5fc47a88c2d +Author: Qaisyousuf +Date: Mon Aug 11 11:28:32 2025 +0200 + + Add frontend condition logic for questionnaire + +commit d1dfcdd2ba6295810c6a92105d4466efa9a40a74 +Author: Qaisyousuf +Date: Fri Aug 8 17:21:29 2025 +0200 + + Implement condition logic for the questionnaire + +commit 9bfed53e7164371d5bacad39a8e53bdff3603886 +Author: Qaisyousuf +Date: Wed Aug 6 14:23:37 2025 +0200 + + Complete subscription and newsletter tracking for new emails in Danish + + Implemented subscription and newsletter tracking with support for new Danish emails. All emails are now delivered to the Primary tab in Gmail for improved visibility. + +commit 13bf203fe42182faaacca226e39ab21803097bc5 +Author: Qaisyousuf +Date: Tue Aug 5 17:59:13 2025 +0200 + + Configure Danish response emails and optimize survey email template for inbox delivery + +commit 24812a77fae855c8cdd27110340859a2cbb65bcf +Author: Qaisyousuf +Date: Tue Aug 5 17:17:06 2025 +0200 + + Configure mail services for primary inbox delivery in Gmail and focused inbox in Outlook + + Updated mail service settings to ensure emails are delivered to the Primary tab in Gmail and the Focused inbox in Outlook. + +commit 285eb3ce931ee870f44fb25b86b85ce6092909b8 +Author: Qaisyousuf +Date: Tue Aug 5 14:22:48 2025 +0200 + + Update email services and improve email template in online survey project + + Replaced the email service implementation and enhanced the email template design. The main email address for sending online surveys is now survey@asurvey.dk. + +commit d06e0c5ba9b4235b8eafdf598914b00bf081805a +Author: Qais Yousuf +Date: Wed Jul 30 14:41:43 2025 +0200 + + add database backup + +commit 196c6887a86769cea4e73db265af9c463b9603c0 +Author: Qais Yousuf +Date: Thu Jun 6 15:24:04 2024 +0200 + + real-time notification completed + +commit aacc23d5ef94ef12940a0cad863503372ca609ec +Author: Qais Yousuf +Date: Sat Jun 1 21:04:36 2024 +0200 + + generate report for pdf and excel completed + +commit 9c560a798caddf2f70e4ac7d11fcb949e7da5301 +Author: Qais Yousuf +Date: Sat Jun 1 18:38:06 2024 +0200 + + user response for all the survey completed + +commit 1254366a650bbd9b2a86e9126907db23e63e3588 +Author: Qais Yousuf +Date: Fri May 10 20:37:42 2024 +0200 + + Email tracking with IP adress completed + +commit 8994421caf6f0ff4bec911ad49bbbb406844b678 +Author: Qais Yousuf +Date: Thu May 9 19:14:25 2024 +0200 + + Real-time email event with charts completed + +commit 4fb4e979e66d45fec42116fc7ca3e569d7e0d2e2 +Author: Qais Yousuf +Date: Thu May 9 14:08:10 2024 +0200 + + Real time email event tracking completed + +commit e80a2675e66485cec323bbae29040add4606867e +Author: Qais Yousuf +Date: Sat May 4 20:19:22 2024 +0200 + + login functionality completed + +commit d733b2cdb15b5b05a1999daec5f0e70f60c1ceca +Author: Qais Yousuf +Date: Wed May 1 17:51:38 2024 +0200 + + Sending the survey to multiple users created + +commit 644893ded8ea1823cd67c5d973e55a0401985f36 +Author: Qais Yousuf +Date: Tue Apr 30 21:27:33 2024 +0200 + + survey analyzer completed for all types of questions + +commit 5b49528a3329d28a3e655c1507a61d38ef3f9ebe +Author: Qais Yousuf +Date: Tue Apr 30 14:28:32 2024 +0200 + + question type of image chart completed + +commit d3a6fd4918ba517d9e18af6a9b97ae500ada6eaf +Author: Qais Yousuf +Date: Tue Apr 30 11:30:33 2024 +0200 + + Survey Analyzer for each survey created + +commit 181237e9ff666013e613cd698a3bca093e62d2c3 +Author: Qais Yousuf +Date: Fri Apr 26 11:40:27 2024 +0200 + + User response backend completed + +commit 98ec7a656101ebb7e0640d160e057ea59ebdcb2c +Author: Qais Yousuf +Date: Tue Apr 23 20:00:09 2024 +0200 + + All question type frontend completed + +commit 1a43f8b456e885cd1a49911359da4ef23e6d7fed +Author: Qais Yousuf +Date: Mon Apr 22 18:11:10 2024 +0200 + + Image and Likret forntend question type completed + +commit a29d11fbcd0a2c58789b623054e3543c5b0f78f6 +Author: Qais Yousuf +Date: Sun Apr 21 19:59:57 2024 +0200 + + ranking question type completed + +commit 89182ca4695b2dc1378f59519b27081fe634269b +Author: Qais Yousuf +Date: Sun Apr 21 16:29:41 2024 +0200 + + sliber question type frontend completed + +commit ab3daa46f6d1f0a1a511833a424a6a4d02e4a4c4 +Author: Qais Yousuf +Date: Fri Apr 19 15:11:18 2024 +0200 + + Response questionnaire for multiple choice completed + +commit 31faec4f73e0d78ad2b5e593e081ebe8e53e214d +Author: Qais Yousuf +Date: Wed Apr 10 19:26:03 2024 +0200 + + response frontend completed + +commit a399126e3b736b9d2b6542795275dacb284f29f0 +Author: Qais Yousuf +Date: Tue Apr 9 18:42:29 2024 +0200 + + URL expiration method completed + +commit 1f8eb6103c7b16cdcaa5ce3faaab8059da189331 +Author: Qais Yousuf +Date: Sun Apr 7 22:11:31 2024 +0200 + + sending email completed + +commit 6bc624dd70382659de65e477eb66b66d9c285078 +Author: Qais Yousuf +Date: Fri Apr 5 17:29:05 2024 +0200 + + User subscription with newsletter completed + +commit 46a75504d8297fb470ef09c999a93a336aa934c0 +Author: Qais Yousuf +Date: Fri Apr 5 17:27:17 2024 +0200 + + Subscription completed + +commit 2a383d0c3d5f7535d2a58526d95ad8f731cc5659 +Author: Qais Yousuf +Date: Wed Apr 3 16:40:00 2024 +0200 + + Subscription design completed + +commit 2ebe7ad5b332f209ca6ea0ca19a0ff46b13c216f +Author: Qais Yousuf +Date: Sat Mar 30 16:10:19 2024 +0100 + + Frontend design completed + +commit 366f0c7bef1917c66470ebbbd04a6444d9e46e22 +Author: Qais Yousuf +Date: Wed Mar 27 11:48:25 2024 +0100 + + Page CURD comleted + +commit 57b89d6456377d02b4e65d43c4822f085c5b2f40 +Author: Qais Yousuf +Date: Tue Mar 26 17:51:26 2024 +0100 + + the questionnaire CURD operation is complete + +commit 64280c893683dec81596c86198d267c4e799dfc0 +Author: Qais Yousuf +Date: Tue Mar 26 16:45:27 2024 +0100 + + Creating multiple question in the edit mode comppleted + +commit 4b6f367545a69f25d1bf7f7b5048531ea1f891d7 +Author: Qais Yousuf +Date: Mon Mar 25 09:53:39 2024 +0100 + + Create new question in the edit questionnaire created + +commit 57ebc7119a8c9c1d79f7937080d17df52df031f5 +Author: Qais Yousuf +Date: Sun Mar 24 17:10:30 2024 +0100 + + create new question in the edit questionnaire is completed + +commit 57a7e4619407c4ee55ffdaaf0c45d544b3b9760d +Author: Qais Yousuf +Date: Sun Mar 24 00:53:00 2024 +0100 + + the deletion of questions in the edit mode + +commit 3c5f0c7010325d4e2e6b483aa425ad7dee62fd51 +Author: Qais Yousuf +Date: Fri Mar 22 19:58:00 2024 +0100 + + the questionnaire create and save designe comppleted + +commit a50d5eb24141398ac4adc2e8dfd8076ab0744e23 +Author: Qais Yousuf +Date: Fri Mar 22 10:32:56 2024 +0100 + + Edit question and Save question functionality added to the edit questionnaire + +commit 729ffc869b0621c741f6be8b8ba2cd4f8e8ca9fa +Author: Qais Yousuf +Date: Thu Mar 21 16:19:27 2024 +0100 + + save and edit functionlity is enabled for the questionnaire + +commit 69810186ebf1b77d9bcb554060f18cbb2a0e26cb +Author: Qais Yousuf +Date: Thu Mar 21 11:00:24 2024 +0100 + + Questionnaire details configured + +commit 9938e696f6f6944396ca607cc4603238a35ddfea +Author: Qais Yousuf +Date: Fri Mar 15 19:40:12 2024 +0100 + + the questionnaire with list of questions and answers added + +commit f83d5c492b765285d38a5d740ee781151a32a4e9 +Author: Qais Yousuf +Date: Tue Mar 12 16:57:42 2024 +0100 + + the questionnaire mode CURD complete + +commit 59d86a516e3c0737042e33c50bdf253b9bb83e21 +Author: Qais Yousuf +Date: Sun Mar 10 13:46:37 2024 +0100 + + the add method of questionnaire created + +commit 78ed96237d788bbe27336cbdd07d49ce95d8f579 +Author: Qais Yousuf +Date: Fri Mar 8 11:20:36 2024 +0100 + + Survey Models Created + +commit 3a8f1405b5beeff4318786a534a8bbf8fa513b64 +Author: Qais Yousuf +Date: Sun Mar 3 13:57:57 2024 +0100 + + config footer + +commit 3b98fd109f2b7743ff11c7a47f05819614fb108c +Author: Qais Yousuf +Date: Thu Feb 22 16:46:42 2024 +0100 + + Banner CURD operation completed + +commit 4a65418344d89789d5875e7871ce6371116569e9 +Author: Qais Yousuf +Date: Wed Feb 21 18:35:32 2024 +0100 + + Banner with the CURD operation + +commit 86d6e8c49d8ecb73b3df32c472fccf50999f531a +Author: Qais Yousuf +Date: Tue Feb 20 18:53:54 2024 +0100 + + Migration added + +commit eac2a698bd5a68117649104e8c1d1f8cbcee290c +Author: Qais Yousuf +Date: Mon Feb 19 15:09:03 2024 +0100 + + Initialize project with basic structure and dependencies + +commit cd2c1959aa6148a8d1cb35e669c0b38d1d3549fb +Author: Qais Yousuf +Date: Mon Feb 19 13:33:24 2024 +0100 + + SurveyVista initial