master #173

Merged
Maxime merged 71 commits from Maxime/Clyde:master into master 2024-04-22 00:07:00 +02:00
6 changed files with 112 additions and 3 deletions
Showing only changes of commit eacdf8d47a - Show all commits

View File

@ -112,11 +112,11 @@ public class MockController {
Researcher output = researchesService.saveResearcher(jojoResearcherAccount); Researcher output = researchesService.saveResearcher(jojoResearcherAccount);
Research jojoResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(), Research jojoResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(0),
PaperType.Article,"here",null,"english", PaperType.Article,"here",null,"english",
Access.OpenSource,"IT","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms"); Access.OpenSource,"IT","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms");
Research restrictedResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(), Research restrictedResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(1111111111),
PaperType.Article,"restricted",null,"english", PaperType.Article,"restricted",null,"english",
Access.Restricted,"Restricted","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms"); Access.Restricted,"Restricted","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms");

View File

@ -0,0 +1,40 @@
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
import ovh.herisson.Clyde.Services.ScientificPublications.StatisticsService;
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
import java.util.Map;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
@AllArgsConstructor
public class StatController {
private StatisticsService statServ;
private ResearchesService researchesServ;
/** returns all the statistics in a 2D array
*
* @param id the researcher's id
* @return all the stats in a 2D array
*/
@GetMapping("/stats/{id}")
public ResponseEntity<Iterable<Iterable<Map<String, Integer>>>> getStat(@PathVariable Long id){
Researcher researcher = researchesServ.getResearcherById(id);
if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
Iterable<Iterable<Map<String,Integer>>> stats = statServ.generateStats(researcher);
if (stats == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(stats,HttpStatus.OK);
}
}

View File

@ -2,8 +2,14 @@ package ovh.herisson.Clyde.Repositories.ScientificPublications;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.ScientificPublications.Research; import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
import java.util.Map;
public interface ResearchRepository extends CrudRepository<Research,Long> { public interface ResearchRepository extends CrudRepository<Research,Long> {
Research findById(long id); Research findById(long id);
Iterable<Research> findByAuthor(Researcher author);
} }

View File

@ -0,0 +1,27 @@
package ovh.herisson.Clyde.Repositories.ScientificPublications;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
import java.util.Map;
public interface StatsRepository extends CrudRepository<Research,Long> {
@Query("select new map(to_char(r.releaseDate, 'month') as label, sum(r.views) as y) from Research r group by to_char(r.releaseDate, 'month')")
Iterable<Map<String ,Integer>> viewsByMonths();
Iterable<Map<String ,Integer>> viewsByYears();
Iterable<Map<String ,Integer>> viewsByTopics();
Iterable<Map<String ,Integer>> coAuthorByMonths();
Iterable<Map<String ,Integer>> coAuthorsByTopics();
Iterable<Map<String ,Integer>> languageByTopics();
Iterable<Map<String ,Integer>> languageByYears();
Iterable<Map<String ,Integer>> languageByMonths();
Iterable<Map<String ,Integer>> researchesByYears();
Iterable<Map<String ,Integer>> researchesByTopics();
Iterable<Map<String ,Integer>> researchesByMonth();
}

View File

@ -0,0 +1,37 @@
package ovh.herisson.Clyde.Services.ScientificPublications;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearcherRepository;
import ovh.herisson.Clyde.Repositories.ScientificPublications.StatsRepository;
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
import java.security.Key;
import java.util.*;
@Service
@AllArgsConstructor
public class StatisticsService {
private ResearchRepository articleRepo;
private StatsRepository statsRepo;
public Iterable<Iterable<Map<String, Integer>>> generateStats(Researcher researcher){
Iterable<Research> researches = articleRepo.findByAuthor(researcher);
if (researches == null) return null;
ArrayList<Iterable<Map<String,Integer>>> toReturn = new ArrayList<>();
toReturn.add(statsRepo.viewsByMonths());
return toReturn;
}
}

View File

@ -32,7 +32,6 @@ public class Research {
@JoinColumn(name ="Researcher") @JoinColumn(name ="Researcher")
private Researcher author; private Researcher author;
@CreationTimestamp
@Column(nullable = false) @Column(nullable = false)
private Date releaseDate; private Date releaseDate;