/* * Copyright (C) 2020 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * * StatoolInfos is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * StatoolInfos is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ package fr.devinsy.statoolinfos.htmlize.charts; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; import org.apache.commons.codec.digest.DigestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.strings.StringList; import fr.devinsy.xidyn.utils.XidynUtils; /** * The Class projectsRawPageBuilder. */ public class FooChartView { private static Logger logger = LoggerFactory.getLogger(FooChartView.class); public static String build() throws StatoolInfosException { String result; try { String source = XidynUtils.load(FooChartView.class.getResource("/fr/devinsy/statoolinfos/htmlize/charts/foo.xhtml")); String code = XidynUtils.extractBodyContent(source); code = code.replaceAll("myChart", "myChart_" + DigestUtils.md5Hex(LocalDateTime.now() + "lineChart")); // DO MonthsBarChart LocalDate start = LocalDate.parse("2020-01-01"); LocalDate end = LocalDate.parse("2020-12-31"); DateCountList dates = new DateCountList(); dates.add(new DateCount("202001", 7)); dates.add(new DateCount("202002", 9)); dates.add(new DateCount("202003", 4)); dates.add(new DateCount("202004", 2)); dates.add(new DateCount("202005", 1)); dates.add(new DateCount("202006", 7)); StringList labels = ChabuUtils.buildYearMonthLabels(start, end); StringList values = ChabuUtils.normalizedMonthCountList(dates, start, end).toValueList(); code = code.replaceAll("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(labels, values)); /* StringList labels = ChabuUtils.buildWeekLabels(LocalDate.parse("2020-01-01"), LocalDate.parse("2020-12-31")); DateCountList dates = project.issueStats().getWeekCreatedIssueCounts(); StringList values = ChabuUtils.normalizedWeekCountList(dates, start, end).toValueList(); code = code.replaceAll("data: \\[.*\\]", "data: " + ChabuUtils.toJSonNumbers(labels, values)); dates = project.issueStats().getWeekConcludedIssueCounts(); values = ChabuUtils.normalizedWeekCountList(dates, start, end).toValueList(); code = code.replaceAll("data: \\[.*\\] ", "data: " + ChabuUtils.toJSonNumbers(labels, values)); */ result = code.toString(); } catch (IOException exception) { throw new StatoolInfosException("Error building foo charts view: " + exception.getMessage(), exception); } // return result; } }