<commit_before>package com.itto3.itimeu;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.itto3.itimeu.data.ItemContract;
import com.itto3.itimeu.data.ItemDbHelper;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class StatisticsFragment extends Fragment implements DatePickerDialog.OnDateSetListener {
    // For access ITimeU database
    ItemDbHelper dbHelper;
    SQLiteDatabase db;

    private Activity mStatisticsActivity;
    private Context mStatisticsContext;

    // Statistics view components
    private Spinner mStatSpinner;
    private LineChart mLineChart;
    private TextView mStatResultText;
    private EditText mStatStartEditText;
    private EditText mStatEndEditText;

    // Spinner item's text
    private String mSpinnerText;

    // Date format
    private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy.MM.dd", Locale.KOREA);
    // Today : Date -> String
    private String mTodayStr;
    // A week ago: Date -> String
    private String mAWeekAgoStr;
    // A month ago: Date -> String
    private String mAMonthAgoStr;

    // Date : year, month, day
    private int mYear;
    private int mMonth;
    private int mDay;
    private String mCustomStart;
    private String mCustomEnd;
    private boolean isClickStartDate;
    private boolean isClickEndDate;

    // ArrayList for units and total units in each days
    private ArrayList<Integer> sumOfDayUnitArrayList;
    private ArrayList<Integer> sumOfDayTotalUnitArrayList;

    // Save date in selected period
    private ArrayList<String> dateArrayList;

    // Accent color for drawing unit chart
    private String mColorAccentStr = "#FF5722";
    private int mColorAccentInt = Color.parseColor(mColorAccentStr);

    // Primary dark color for text
    private String mColorDarkStr = "#616161";
    private int mColorDarkInt = Color.parseColor(mColorDarkStr);

    // Primary color for drawing total unit chart
    private String mColorStr = "#9E9E9E";
    private int mColorInt = Color.parseColor(mColorStr);

    // Object for showing toast message
    SimpleToast toast;

    final static int WEEK_PERIOD = 1;
    final static int MONTH_PERIOD = 2;
    final static int CUSTOM_PERIOD = 3;
    private int selectedPeriod = 0;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             Bundle savedInstanceState) {
        // Set identifier
        View mStatisticsView = inflater.inflate(R.layout.fragment_statistics, container, false);
        mStatisticsActivity = getActivity();
        mStatisticsContext = mStatisticsView.getContext();

        String statisticsTag = getTag();
        ((MainActivity) getActivity()).setStatisticsTag(statisticsTag);

        dbHelper = new ItemDbHelper(mStatisticsContext);
        db = dbHelper.getReadableDatabase();

        // Get id from fragment_statistics
        mStatSpinner = mStatisticsView.findViewById(R.id.stat_spinner);
        selectedSpinnerItem();

        // Get chart view
        mLineChart = mStatisticsView.findViewById(R.id.chart);

        // Get result text view
        mStatResultText = mStatisticsView.findViewById(R.id.stat_result);

        // Get period edit text view
        mStatStartEditText = mStatisticsView.findViewById(R.id.start_edit_txt);
        mStatEndEditText = mStatisticsView.findViewById(R.id.end_edit_txt);

        return mStatisticsView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);

        toast = new SimpleToast(mStatisticsContext);
    }

    /**
     * Set data to chart view
     */
    private void addData() {
        // Unit data
        List<Entry> unitList = new ArrayList<>();

        for (int i = 0; i < sumOfDayUnitArrayList.size(); i++) {
            unitList.add(new Entry(i, sumOfDayUnitArrayList.get(i)));
        }

        // Units line data set
        LineDataSet unitDataSet = new LineDataSet(unitList, getString(R.string.unit_label));
        customLineDataSet(unitDataSet, mColorAccentInt);

        // Total unit data
        List<Entry> totalUnitEntries = new ArrayList<>();

        for (int i = 0; i < sumOfDayTotalUnitArrayList.size(); i++) {
            totalUnitEntries.add(new Entry(i, sumOfDayTotalUnitArrayList.get(i)));
        }

        // Total units line data set
        LineDataSet totalUnitDataSet = new LineDataSet(totalUnitEntries,
                getString(R.string.total_unit_label));
        customLineDataSet(totalUnitDataSet, mColorDarkInt);

        // Set x-axis<commit_msg>토스트 메세지에서 컨텍스트가 null로 입력되는 버그 픽스<commit_after>package com.itto3.itimeu;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.itto3.itimeu.data.ItemContract;
import com.itto3.itimeu.data.ItemDbHelper;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class StatisticsFragment extends Fragment implements DatePickerDialog.OnDateSetListener {
    // For access ITimeU database
    ItemDbHelper dbHelper;
    SQLiteDatabase db;

    private Activity mStatisticsActivity;
    private Context mStatisticsContext;

    // Statistics view components
    private Spinner mStatSpinner;
    private LineChart mLineChart;
    private TextView mStatResultText;
    private EditText mStatStartEditText;
    private EditText mStatEndEditText;

    // Spinner item's text
    private String mSpinnerText;

    // Date format
    private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy.MM.dd", Locale.KOREA);
    // Today : Date -> String
    private String mTodayStr;
    // A week ago: Date -> String
    private String mAWeekAgoStr;
    // A month ago: Date -> String
    private String mAMonthAgoStr;

    // Date : year, month, day
    private int mYear;
    private int mMonth;
    private int mDay;
    private String mCustomStart;
    private String mCustomEnd;
    private boolean isClickStartDate;
    private boolean isClickEndDate;

    // ArrayList for units and total units in each days
    private ArrayList<Integer> sumOfDayUnitArrayList;
    private ArrayList<Integer> sumOfDayTotalUnitArrayList;

    // Save date in selected period
    private ArrayList<String> dateArrayList;

    // Accent color for drawing unit chart
    private String mColorAccentStr = "#FF5722";
    private int mColorAccentInt = Color.parseColor(mColorAccentStr);

    // Primary dark color for text
    private String mColorDarkStr = "#616161";
    private int mColorDarkInt = Color.parseColor(mColorDarkStr);

    // Primary color for drawing total unit chart
    private String mColorStr = "#9E9E9E";
    private int mColorInt = Color.parseColor(mColorStr);

    // Object for showing toast message
    SimpleToast toast;

    final static int WEEK_PERIOD = 1;
    final static int MONTH_PERIOD = 2;
    final static int CUSTOM_PERIOD = 3;
    private int selectedPeriod = 0;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             Bundle savedInstanceState) {
        // Set identifier
        View mStatisticsView = inflater.inflate(R.layout.fragment_statistics, container, false);
        mStatisticsActivity = getActivity();
        mStatisticsContext = mStatisticsView.getContext();
        toast = new SimpleToast(mStatisticsContext);

        String statisticsTag = getTag();
        ((MainActivity) getActivity()).setStatisticsTag(statisticsTag);

        dbHelper = new ItemDbHelper(mStatisticsContext);
        db = dbHelper.getReadableDatabase();

        // Get id from fragment_statistics
        mStatSpinner = mStatisticsView.findViewById(R.id.stat_spinner);
        selectedSpinnerItem();

        // Get chart view
        mLineChart = mStatisticsView.findViewById(R.id.chart);

        // Get result text view
        mStatResultText = mStatisticsView.findViewById(R.id.stat_result);

        // Get period edit text view
        mStatStartEditText = mStatisticsView.findViewById(R.id.start_edit_txt);
        mStatEndEditText = mStatisticsView.findViewById(R.id.end_edit_txt);

        return mStatisticsView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    /**
     * Set data to chart view
     */
    private void addData() {
        // Unit data
        List<Entry> unitList = new ArrayList<>();

        for (int i = 0; i < sumOfDayUnitArrayList.size(); i++) {
            unitList.add(new Entry(i, sumOfDayUnitArrayList.get(i)));
        }

        // Units line data set
        LineDataSet unitDataSet = new LineDataSet(unitList, getString(R.string.unit_label));
        customLineDataSet(unitDataSet, mColorAccentInt);

        // Total unit data
        List<Entry> totalUnitEntries = new ArrayList<>();

        for (int i = 0; i < sumOfDayTotalUnitArrayList.size(); i++) {
            totalUnitEntries.add(new Entry(i, sumOfDayTotalUnitArrayList.get(i)));
        }

        // Total units line data set
        LineDataSet totalUnitDataSet = new LineDataSet(totalUnitEntries,
                getString(R.string.total_unit_label));
        customLineDataSet(totalUnitDataSet, mColorDarkInt);

        // Set x-axis
{'fraction_non_alphanumeric': 0.0845213849287169, 'fraction_numerical': 0.003903598099117447, 'mean_word_length': 3.443815987933635, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '4263903', 'n_tokens_mistral': 3401, 'n_tokens_neox': 3295, 'n_words': 813}