<commit_before>package com.noprestige.kanaquiz.logs;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jjoe64.graphview.DefaultLabelFormatter;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.BarGraphSeries;
import com.jjoe64.graphview.series.DataPoint;
import com.noprestige.kanaquiz.R;

import org.threeten.bp.LocalDate;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

public class LogDetailView extends AppCompatActivity
{
    static class FetchLogDetails extends AsyncTask<LogDetailView, TextView, Integer>
    {
        @SuppressLint("StaticFieldLeak")
        LinearLayout layout;
        @SuppressLint("StaticFieldLeak")
        TextView lblLogMessage;
        @SuppressLint("StaticFieldLeak")
        GraphView logGraph;
        BarGraphSeries<DataPoint> graphSeries;
        List<String> staticLabels;

        @Override
        protected void onPreExecute()
        {
            graphSeries = new BarGraphSeries<>();
            staticLabels = new ArrayList<>();
        }

        @Override
        protected Integer doInBackground(LogDetailView... activity)
        {
            layout = activity[0].findViewById(R.id.logViewLayout);
            lblLogMessage = activity[0].findViewById(R.id.lblLogMessage);
            logGraph = activity[0].findViewById(R.id.logGraph);

            QuestionRecord[] records = LogDatabase.DAO.getDatesQuestionRecords(activity[0].date);

            logGraph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter()
            {
                @Override
                public String formatLabel(double value, boolean isValueX)
                {
                    if (isValueX)
                    {
                        int key = (int) Math.floor(value);
                        return ((key >= 0) && (key < staticLabels.size())) ? staticLabels.get(key) : null;
                    }
                    else
                        return super.formatLabel(value, isValueX);
                }
            });

            if (records.length == 0)
                return 0;

            graphSeries.setSpacing(10);
            graphSeries.setDataWidth(1.0);
            graphSeries.appendData(new DataPoint(0, 0), true, 1000, true);

            for (QuestionRecord record : records)
            {
                TextView output = new TextView(activity[0].getBaseContext());

                output.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14,
                        activity[0].getResources().getDisplayMetrics()));
                output.setText(record.getQuestion() + "     " + record.getCorrectAnswers() + '/' +
                        (record.getCorrectAnswers() + record.getIncorrectAnswers()));

                graphSeries.appendData(new DataPoint(staticLabels.size() + 0.5, (record.getCorrectAnswers() * 100) /
                        (record.getCorrectAnswers() + record.getIncorrectAnswers())), true, 1000, true);

                staticLabels.add(record.getQuestion());

                if (isCancelled())
                    return null;
                else
                    publishProgress(output);
            }
            return records.length;
        }

        @Override
        protected void onProgressUpdate(TextView... item)
        {
            layout.addView(item[0], layout.getChildCount() - 1);
            logGraph.getViewport().setMaxX(staticLabels.size());
            logGraph.removeAllSeries();
            logGraph.addSeries(graphSeries);
        }

        @Override
        protected void onCancelled()
        {
            layout = null;
            lblLogMessage = null;
            logGraph = null;
        }

        @Override
        protected void onPostExecute(Integer count)
        {
            if (count > 0)
            {
                layout.removeView(lblLogMessage);

                graphSeries.appendData(new DataPoint(staticLabels.size(), 0), true, 1000, true);
                logGraph.removeAllSeries();
                logGraph.addSeries(graphSeries);
            }
            else
                lblLogMessage.setText(R.string.no_logs);
        }<commit_msg>Separated graph padding<commit_after>package com.noprestige.kanaquiz.logs;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jjoe64.graphview.DefaultLabelFormatter;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.BarGraphSeries;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.PointsGraphSeries;
import com.noprestige.kanaquiz.R;

import org.threeten.bp.LocalDate;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

public class LogDetailView extends AppCompatActivity
{
    static class FetchLogDetails extends AsyncTask<LogDetailView, TextView, Integer>
    {
        @SuppressLint("StaticFieldLeak")
        LinearLayout layout;
        @SuppressLint("StaticFieldLeak")
        TextView lblLogMessage;
        @SuppressLint("StaticFieldLeak")
        GraphView logGraph;
        BarGraphSeries<DataPoint> graphSeries;
        List<String> staticLabels;

        @Override
        protected void onPreExecute()
        {
            graphSeries = new BarGraphSeries<>();
            staticLabels = new ArrayList<>();
        }

        @Override
        protected Integer doInBackground(LogDetailView... activity)
        {
            layout = activity[0].findViewById(R.id.logViewLayout);
            lblLogMessage = activity[0].findViewById(R.id.lblLogMessage);
            logGraph = activity[0].findViewById(R.id.logGraph);

            QuestionRecord[] records = LogDatabase.DAO.getDatesQuestionRecords(activity[0].date);

            logGraph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter()
            {
                @Override
                public String formatLabel(double value, boolean isValueX)
                {
                    if (isValueX)
                    {
                        int key = (int) Math.floor(value);
                        return ((key >= 0) && (key < staticLabels.size())) ? staticLabels.get(key) : null;
                    }
                    else
                        return super.formatLabel(value, isValueX);
                }
            });

            if (records.length == 0)
                return 0;

            graphSeries.setSpacing(10);
            graphSeries.setDataWidth(1.0);

            for (QuestionRecord record : records)
            {
                TextView output = new TextView(activity[0].getBaseContext());

                output.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14,
                        activity[0].getResources().getDisplayMetrics()));
                output.setText(record.getQuestion() + "     " + record.getCorrectAnswers() + '/' +
                        (record.getCorrectAnswers() + record.getIncorrectAnswers()));

                graphSeries.appendData(new DataPoint(staticLabels.size() + 0.5, (record.getCorrectAnswers() * 100) /
                        (record.getCorrectAnswers() + record.getIncorrectAnswers())), true, 1000, true);

                staticLabels.add(record.getQuestion());

                if (isCancelled())
                    return null;
                else
                    publishProgress(output);
            }
            return records.length;
        }

        @Override
        protected void onProgressUpdate(TextView... item)
        {
            layout.addView(item[0], layout.getChildCount() - 1);
            logGraph.getViewport().setMaxX(staticLabels.size());
            logGraph.removeAllSeries();
            logGraph.addSeries(graphSeries);
        }

        @Override
        protected void onCancelled()
        {
            layout = null;
            lblLogMessage = null;
            logGraph = null;
        }

        @Override
        protected void onPostExecute(Integer count)
        {
            if (count > 0)
            {
                layout.removeView(lblLogMessage);

                PointsGraphSeries<DataPoint> graphPadding = new PointsGraphSeries<>();
                graphPadding.setSize(0);
                graphPadding.appendData(new DataPoint(0, 0), true, 1000, true);
                graphPadding.appendData(new DataPoint(staticLabels.size(), 0), true, 1000, true);
                logGraph.addSeries(graphPadding);
            }
            else
                lblLogMessage.setText(R.string.no_logs);
        }
{'fraction_non_alphanumeric': 0.09783206778914934, 'fraction_numerical': 0.010454495433036205, 'mean_word_length': 1.9993399339933993, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '937404', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2299, 'n_words': 406}