Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Analyze phipu2 #84

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions analyze/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# Analyzer
# NoScope360 Analyze Service

The analyzer reads the data from Elasticsearch, transforms it according to the indicator definitions and makes it available to the frontend in a unified format as a REST API.
The NoScope360 Analyze Service is a robust Spring Boot application designed to handle operations related to
municipalities and surveys, offering capabilities such as fetching detailed municipality insights, computing average
ratings, managing and processing survey data, and more.

### Features

* **Municipality Operations:** Get a comprehensive overview of municipalities, detailed information on specific
municipalities based on ID, and compute statistics for all municipalities.
* **Survey Management:** Access a broad overview of all available surveys, fetch specific surveys by ID, view statistics
related to surveys, and process answers for given surveys.
* **Exception Handling:** Custom exception handling to handle scenarios such as invalid inputs and not-found resources.

### Dependencies

* **Spring Boot:** The backbone of our service, facilitating quick and efficient development.
* **SLF4J:** Logging framework integrated to provide insights into operations and assist with debugging.
* **Repositories:** Interaction with the database is facilitated using various repositories like
QuantitativeDataRepository, QualitativeDataRepository, MunicipalityRepository, and more.
* **SurveyClient:** An external client used for interactions related to survey operations.

### Quick Start

1. Clone the repository:

```bash
git clone [repository_url]
```

2. Navigate to the project directory:

```bash
cd noscope360-analyze-service
```

3. Build the project:

```bash
mvn clean install
```

4. Run the application:

```bash
mvn spring-boot:run
```

### Future Enhancements

* Implement the outstanding `TODO` features in the `SurveyService`.
* Extend the application to incorporate more granular insights related to municipalities and surveys.
* Integrate with more data sources to enhance the comprehensiveness of our analysis.
8 changes: 6 additions & 2 deletions analyze/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>io.natron.noscope360</groupId>
<artifactId>analyze</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.1.2</version>
<name>analyze</name>
<description>analyze</description>
<description>A comprehensive Spring Boot service for analyzing municipality data and managing surveys.</description>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public List<MunicipalityOverviewDto> getMunicipalities() {
* @return {@link MunicipalityStatsDto} representing the statistics of all municipalities.
*/
public MunicipalityStatsDto getMunicipalitiesStats() {
log.info("Computing statistics for all municipalities...");
log.info("Computing statistics over all municipalities...");

List<MunicipalityOverviewDto> municipalities = getMunicipalities();
int totalMunicipalities = municipalities.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.util.List;

/**
* Service responsible for managing and processing survey data.
*/
@Service
public class SurveyService {

Expand All @@ -22,31 +25,73 @@ public class SurveyService {
private final SurveyClient surveyClient;
private final QualitativeDataRepository qualitativeDataRepository;

/**
* Constructor to initialize the SurveyService with the required dependencies.
*
* @param surveyClient client to interact with survey API.
* @param qualitativeDataRepository repository to fetch qualitative data.
*/
public SurveyService(SurveyClient surveyClient, QualitativeDataRepository qualitativeDataRepository) {
this.surveyClient = surveyClient;
this.qualitativeDataRepository = qualitativeDataRepository;

log.info("SurveyService initialized.");
}

/**
* Fetches an overview of all available surveys.
*
* @return a list of SurveyOverviewDto representing all surveys.
*/
public List<SurveyOverviewDto> getSurveys() {
log.info("Fetching overview for all surveys...");
// TODO: Implement the logic to get the surveys overview. Not implemented due to time constraints.
return null;
}

/**
* Provides statistics related to surveys.
*
* @return a SurveyStatsDto containing survey statistics.
*/
public SurveyStatsDto getSurveyStats() {
log.info("Computing statistics over all surveys...");
// TODO: Implement the logic to get the survey stats. Not implemented due to time constraints.
return null;
}

/**
* Fetches a specific survey by its ID.
*
* @param id the unique identifier of the survey.
* @return a SurveyDto representing the requested survey.
*/
public SurveyDto getSurveyById(String id) {
log.info("Fetching details for survey with ID: {}", id);
// TODO: Implement the logic to get a details of a survey by ID. Not implemented due to time constraints.
return null;
}

/**
* Generates answers for a survey.
*
* @param id the unique identifier of the survey.
* @param surveyAnswersDto the DTO containing the survey answers data.
* @return a SurveyAnswersDto containing the processed survey answers.
* @throws SurveyNotFoundException if the survey is not found.
* @throws InvalidInputException if the provided ID and ID in the request body are not matching.
*/
public SurveyAnswersDto makeSurveyAnswers(String id, SurveyAnswersDto surveyAnswersDto) throws SurveyNotFoundException, InvalidInputException {
log.info("Adding answers for survey with ID: {}", id);

if (!surveyClient.callSurveyAPI(id)) {
throw new SurveyNotFoundException("Survey not found: " + id);
}
if (!id.equals(surveyAnswersDto.id())) {
throw new InvalidInputException("Given ID and ID in the request body are not matching.");
}

// TODO: Implement the logic to add answers for a survey. Not implemented due to time constraints.
return null;
}
}