<commit_before>package de.mvbonline.jmeteranalyzer.backend.graph;

import de.mvbonline.jmeteranalyzer.backend.base.Analyzer;
import net.lingala.zip4j.core.ZipFile;
import org.apache.commons.io.IOUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by mholz on 14.12.2015.
 */
public class GraphAnalyzer implements Analyzer {

    private static final int PAGE_SIZE = 100_000;

    @Override
    public void analyze(Connection sqliteConnection, List<String> tables, PrintWriter resultsFileWriter, File resultDir) throws Exception {

        boolean written = false;

        for (String table : tables) {
            System.out.println("Creating graph files for " + table + "...");
            long results = 0;

            while(true) {
                StringBuilder jsData = new StringBuilder();
                String delim = "";

                Date start = null;
                Date end = null;

                try(Statement statement = sqliteConnection.createStatement()) {
                    String sql = "SELECT timestamp, duration, success FROM '" + table + "' ORDER BY timestamp ASC LIMIT " + PAGE_SIZE + " OFFSET " + results;
                    try(ResultSet resultSet = statement.executeQuery(sql)) {
                        boolean foundAny = false;
                        while(resultSet.next()) {
                            foundAny = true;


                            long timestamp = resultSet.getLong("timestamp");
                            if(start == null) {
                                start = new Date(timestamp);
                            }
                            end = new Date(timestamp);

                            jsData.append(delim);
                            delim = ",\n";

                            jsData.append("{date: ");
                            jsData.append(timestamp).append(", \n");

                            boolean success = resultSet.getBoolean("success");
                            if(success) {
                                jsData.append("lineColor: '#5fb503',");
                            } else {
                                jsData.append("lineColor: '#ff0000',");
                            }

                            jsData.append("duration: ");

                            long duration = resultSet.getLong("duration");
                            jsData.append(duration).append("}");

                            results++;
                        }

                        if(!foundAny) {
                            break;
                        }
                    }
                }

                System.out.println("Writing page...");<commit_msg>Output is a bit prettier now<commit_after>package de.mvbonline.jmeteranalyzer.backend.graph;

import de.mvbonline.jmeteranalyzer.backend.base.Analyzer;
import net.lingala.zip4j.core.ZipFile;
import org.apache.commons.io.IOUtils;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by mholz on 14.12.2015.
 */
public class GraphAnalyzer implements Analyzer {

    private static final int PAGE_SIZE = 100_000;

    @Override
    public void analyze(Connection sqliteConnection, List<String> tables, PrintWriter resultsFileWriter, File resultDir) throws Exception {

        boolean written = false;

        for (String table : tables) {
            System.out.println("Creating graph files for " + table + "...");
            long results = 0;

            while(true) {
                StringBuilder jsData = new StringBuilder();
                String delim = "";

                Date start = null;
                Date end = null;

                try(Statement statement = sqliteConnection.createStatement()) {
                    String sql = "SELECT timestamp, duration, success FROM '" + table + "' ORDER BY timestamp ASC LIMIT " + PAGE_SIZE + " OFFSET " + results;
                    try(ResultSet resultSet = statement.executeQuery(sql)) {
                        boolean foundAny = false;
                        while(resultSet.next()) {
                            foundAny = true;

                            long timestamp = resultSet.getLong("timestamp");
                            if(start == null) {
                                start = new Date(timestamp);
                            }
                            end = new Date(timestamp);

                            jsData.append(delim);
                            delim = ",\n";

                            jsData.append("{date: ");
                            jsData.append(timestamp).append(", \n");

                            boolean success = resultSet.getBoolean("success");
                            if(success) {
                                jsData.append("lineColor: '#5fb503',\n");
                            } else {
                                jsData.append("lineColor: '#ff0000',\n");
                            }

                            jsData.append("duration: ");

                            long duration = resultSet.getLong("duration");
                            jsData.append(duration).append("}");

                            results++;
                        }

                        if(!foundAny) {
                            break;
                        }
                    }
                }

                System.out.println("Writing page...");
{'fraction_non_alphanumeric': 0.09830391138802354, 'fraction_numerical': 0.008307372793354102, 'mean_word_length': 1.305145592341444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '260938', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1305, 'n_words': 298}