Skip to content

Commit

Permalink
AI Generated impact score
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Dec 16, 2024
1 parent 37d90dc commit 3927fb0
Show file tree
Hide file tree
Showing 13 changed files with 606 additions and 399 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/open4goods/api/config/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ SerialisationService serialisationService() {

@Bean
VerticalsGenerationService verticalsGenerationService(ProductRepository pRepo, SerialisationService serialisationService, LegacyAiService aiService, GoogleTaxonomyService gTaxoService, VerticalsConfigService verticalsConfigService, ResourcePatternResolver resourceResolver,
EvaluationService evaluationService, IcecatService icecatService) throws SAXException {
return new VerticalsGenerationService(apiProperties.getVerticalsGenerationConfig(), pRepo, serialisationService, aiService, gTaxoService, verticalsConfigService, resourceResolver, evaluationService, icecatService);
EvaluationService evaluationService, IcecatService icecatService, GenAiService genAiService) throws SAXException {
return new VerticalsGenerationService(apiProperties.getVerticalsGenerationConfig(), pRepo, serialisationService, aiService, gTaxoService, verticalsConfigService, resourceResolver, evaluationService, icecatService, genAiService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ public VerticalsGenerationController(VerticalsGenerationService verticalsGenServ
this.verticalsConfigService = verticalsConfigService;
}

@GetMapping(path="/fullFromDb")
@Operation(summary="Loads the mappings from database, then clean and save to file")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void full() throws ResourceNotFoundException, IOException {
verticalsGenService.fullFromDb();
}

@GetMapping(path="/mappings/load/database")
@Operation(summary="Loads the mappings from database")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void load() throws ResourceNotFoundException {
verticalsGenService.loadCategoriesMappingFromDatabase();
}

@GetMapping(path="/mappings/load/file")
@Operation(summary="Import the mapping file from JSON")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void importMapping() throws ResourceNotFoundException, IOException {
verticalsGenService.importMappingFile();
}
// @GetMapping(path="/fullFromDb")
// @Operation(summary="Loads the mappings from database, then clean and save to file")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public void full() throws ResourceNotFoundException, IOException {
// verticalsGenService.fullFromDb();
// }
//
// @GetMapping(path="/mappings/load/database")
// @Operation(summary="Loads the mappings from database")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public void load() throws ResourceNotFoundException {
// verticalsGenService.loadCategoriesMappingFromDatabase();
// }
//
// @GetMapping(path="/mappings/load/file")
// @Operation(summary="Import the mapping file from JSON")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public void importMapping() throws ResourceNotFoundException, IOException {
// verticalsGenService.importMappingFile();
// }


// @GetMapping(path="/mappings/clean/threshold")
Expand All @@ -81,105 +81,118 @@ public void importMapping() throws ResourceNotFoundException, IOException {



@GetMapping(path="/mappings")
@Operation(summary="Show the mappings")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public Map<String, VerticalCategoryMapping> get() throws ResourceNotFoundException {
return verticalsGenService.getMappings();

}
// @GetMapping(path="/mappings")
// @Operation(summary="Show the mappings")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public Map<String, VerticalCategoryMapping> get() throws ResourceNotFoundException {
// return verticalsGenService.getMappings();
//
// }
//
// @GetMapping(path="/mappings/export")
// @Operation(summary="Export the mapping file to JSON")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public void exportMapping() throws ResourceNotFoundException, IOException {
// verticalsGenService.exportMappingFile();
//
// }


@GetMapping(path="/mappings/export")
@Operation(summary="Export the mapping file to JSON")


@GetMapping(path="/misc/vertical")
@Operation(summary="Generate the vertical files. Please, use https://docs.google.com/spreadsheets/d/1AyBdagWbn_rst2xZvUH9dVF7G2y_Wm_Xrq0IxDGkXoc/edit?gid=0#gid=0")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void exportMapping() throws ResourceNotFoundException, IOException {
verticalsGenService.exportMappingFile();
// Respond to https://docs.google.com/spreadsheets/d/1AyBdagWbn_rst2xZvUH9dVF7G2y_Wm_Xrq0IxDGkXoc/edit?gid=0#gid=0
public void generateCategoryMappingsFragment(
@RequestParam String googleTaxonomyId,
@RequestParam String matchingCategories,
@RequestParam String urlPrefix,
@RequestParam String h1Prefix,
@RequestParam String verticalHomeUrl,
@RequestParam String verticalHomeTitle) throws ResourceNotFoundException, IOException {

verticalsGenService.verticalTemplatetoFile(googleTaxonomyId, matchingCategories, urlPrefix, h1Prefix, verticalHomeUrl, verticalHomeTitle);

}


@GetMapping(path="/assist/attributes/{vertical}")
@GetMapping(path="/{vertical}/attributes/")
@Operation(summary="Generate attributes coverage for a vertical")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
@Cacheable(keyGenerator = CacheConstants.KEY_GENERATOR, cacheNames = CacheConstants.ONE_HOUR_LOCAL_CACHE_NAME)
public VerticalAttributesStats generateAttributesCoverage(@PathVariable String vertical) throws ResourceNotFoundException, IOException {
return verticalsGenService.attributesStats(vertical);

}


@GetMapping(path="/assist/categories/gtin")
@Operation(summary="Generate the categories yaml fragment for a given match")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
@Cacheable(keyGenerator = CacheConstants.KEY_GENERATOR, cacheNames = CacheConstants.ONE_HOUR_LOCAL_CACHE_NAME)
public String generateCategoryMappingsFragment(@RequestParam String gtins) throws ResourceNotFoundException, IOException {
return verticalsGenService.generateCategoryMappingFragmentForGtin(Arrays.asList(gtins.split(",")), null );

}
// @GetMapping(path="/misc/categories/gtin")
// @Operation(summary="Generate the categories yaml fragment for a given match")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// @Cacheable(keyGenerator = CacheConstants.KEY_GENERATOR, cacheNames = CacheConstants.ONE_HOUR_LOCAL_CACHE_NAME)
// public String generateCategoryMappingsFragment(@RequestParam String gtins) throws ResourceNotFoundException, IOException {
// return verticalsGenService.generateCategoryMappingFragmentForGtin(Arrays.asList(gtins.split(",")), null );
//
// }


@GetMapping(path="/assist/categories/vertical")
@GetMapping(path="/{vertical}/categories/")
@Operation(summary="Generate the categories yaml fragment for a given vertical")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
@Cacheable(keyGenerator = CacheConstants.KEY_GENERATOR, cacheNames = CacheConstants.ONE_HOUR_LOCAL_CACHE_NAME)
public String generateCategoryMappingsForExistinf(@RequestParam String vertical, @RequestParam(defaultValue = "5") Integer minOffersCount ) throws ResourceNotFoundException, IOException {
public String generateCategoryMappingsForExistinf(@PathVariable String vertical, @RequestParam(defaultValue = "5") Integer minOffersCount ) throws ResourceNotFoundException, IOException {

VerticalConfig vc = verticalsConfigService.getConfigById(vertical);
return verticalsGenService.generateMapping(vc,minOffersCount);

}






@GetMapping(path="/assist/vertical")
@Operation(summary="Generate the vertical file")
@GetMapping(path="/{vertical}/ecoscore/")
@Operation(summary="Generate the ecoscore yaml fragment for a given vertical")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void generateCategoryMappingsFragment(
@RequestParam String googleTaxonomyId,
@RequestParam String matchingCategories,
@RequestParam String urlPrefix,
@RequestParam String h1Prefix,
@RequestParam String verticalHomeUrl,
@RequestParam String verticalHomeTitle) throws ResourceNotFoundException, IOException {

verticalsGenService.verticalTemplatetoFile(googleTaxonomyId, matchingCategories, urlPrefix, h1Prefix, verticalHomeUrl, verticalHomeTitle);
@Cacheable(keyGenerator = CacheConstants.KEY_GENERATOR, cacheNames = CacheConstants.ONE_HOUR_LOCAL_CACHE_NAME)
public String generateEcoscoreMappings(@PathVariable String vertical) throws ResourceNotFoundException, IOException {

VerticalConfig vc = verticalsConfigService.getConfigById(vertical);
return verticalsGenService.generateEcoscoreYamlConfig(vc);

}




@GetMapping(path="/update/verticals/categoriesmapping")
@Operation(summary="Update the categories mapping directly in the files !")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void updateVerticalsWithMappings(
@RequestParam (defaultValue = "3") Integer minOffers) throws ResourceNotFoundException, IOException {

//TODO(p2,conf) : from conf
verticalsGenService.updateVerticalsWithMappings("/home/goulven/git/open4goods/verticals/src/main/resources/verticals/",minOffers);

}

@GetMapping(path="/update/verticals/categoriesmapping/{vertical}")


// @GetMapping(path="/update/verticals/categoriesmapping")
// @Operation(summary="Update the categories mapping directly in the files !")
// @PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
// public void updateVerticalsWithMappings(
// @RequestParam (defaultValue = "3") Integer minOffers) throws ResourceNotFoundException, IOException {
//
// //TODO(p2,conf) : from conf
// verticalsGenService.updateAllVerticalFileWithCategories("/home/goulven/git/open4goods/verticals/src/main/resources/verticals/",minOffers);
//
// }

@GetMapping(path="/{vertical}/categories/update")
@Operation(summary="Update the categories mapping for a given vertical directly in the file !")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void updateVerticalWithMappings(
@RequestParam (defaultValue = "tv") String vertical,
@PathVariable String vertical,
@RequestParam (defaultValue = "3") Integer minOffers) throws ResourceNotFoundException, IOException {

//TODO(p2,conf) : from conf
verticalsGenService.updateVerticalFileWithCategories(minOffers, "/home/goulven/git/open4goods/verticals/src/main/resources/verticals/"+vertical+".yml");

}

@GetMapping(path="/update/verticals/attributes/{vertical}")
@GetMapping(path="/{vertical}/attributes/update")
@Operation(summary="Update the suggested attributes for a given vertical directly in the file !")
@PreAuthorize("hasAuthority('"+RolesConstants.ROLE_ADMIN+"')")
public void updateVerticalWithAttributes(
@RequestParam (defaultValue = "tv") String vertical,
@PathVariable String vertical,
@RequestParam (defaultValue = "10") Integer minCoverage,
@RequestParam (defaultValue = "") String containing
) throws ResourceNotFoundException, IOException {
Expand Down
Loading

0 comments on commit 3927fb0

Please sign in to comment.