<commit_before>package deltadak;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.input.*;
import javafx.scene.layout.GridPane;
import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter;

import java.net.URL;
import java.util.ResourceBundle;

import jdk.nashorn.internal.runtime.ECMAException;

import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.ResourceBundle;

import static java.lang.Integer.min;

public class Controller implements Initializable {
    @FXML ListView<String> day1;
    @FXML ListView<String> day2;
    @FXML GridPane gridpane;

    Connection connection;
    Statement statement;
    int countID = 1;
    ArrayList<String[]> dayOne = new ArrayList<>(); // containing "task", "label"
    ArrayList<String[]> dayTwo = new ArrayList<>();
    Calendar dayOneCal;
    Calendar dayTwoCal;


    /**
     * Initialization method for the controller.
     */
    @FXML public void initialize(URL location, ResourceBundle resourceBundle){

//        deleteTable("tasks");
//        createTable();

        Calendar dayOneCal = Calendar.getInstance();
//        insertTask(dayOneCal, "exam1", "2WA60",1);
//        insertTask(dayOneCal, "exam2", "2WA60",2);
//        insertTask(dayOneCal, "exam3", "2WA30",3);
//        insertTask(dayOneCal, "exam4", "2WA30",4);
//        deleteTasksDay(calendar);

        getTasksDay(dayOneCal, true);
        Calendar dayTwoCal = Calendar.getInstance();
        dayTwoCal.add(Calendar.DAY_OF_MONTH,1);
//        insertTask(dayTwoCal, "one", "2WA60",1);
//        insertTask(dayTwoCal, "two", "2WA60",2);
//        insertTask(dayTwoCal, "three", "2WA30",3);
//        insertTask(dayTwoCal, "boom", "2WA30",4);

        getTasksDay(dayTwoCal, false);
        putTasksDay(true);
        putTasksDay(false);
        setupGridPane();

    }

    /**
     * database communication below -----------------------------------------------------
     */

    /**
     * inserts a task into the database, given
     * @param dayCal - the date as a Calendar
     * @param task - the task as a string
     * @param label - the label/course (code) as a string
     * @param order - this is the i-th task on this day, as an int
     */
    public void insertTask(Calendar dayCal, String task, String label, int order) {
        getHighestID();

        String dayString = calendarToString(dayCal);

        String sql = "INSERT INTO tasks(id, day, task, label, orderInDay) " +
                    "VALUES (" + countID + ", '" + dayString + "', '" + task + "','" + label + "'," + order + ")";
        countID++;
        query(sql);
    }

    /**
     * Gets all the tasks on a given day, and stores them in dayOne if dayOneBoolean is true.
     * Stores them in dayTwo otherwise.
     *
     * This method is used to get a day from the database for which we are going to update its tasks.
     * THE CURRENT TASKS GET REMOVED!
     * -> The new tasks will be put back with putTasksDay
     *
     * @param dayCal - the date for which to get all the tasks
     * @param dayOneBoolean
     */
    public void getTasksDay(Calendar dayCal, boolean dayOneBoolean) {
        if(dayOneBoolean) {
            dayOneCal = dayCal;
        } else {
            dayTwoCal = dayCal;
        }

        String dayString = calendarToString(dayCal);
        String sql = "SELECT task, label FROM tasks WHERE day = '" + dayString + "' ORDER BY orderInDay";

        setConnection();
        try {
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()) {
                String[] task = {resultSet.getString("task"), resultSet.getString("label")};
                if(dayOneBoolean) {
                    dayOne.add(task);
                } else {
                    dayTwo.add(task);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // remove things from the day we are going to edit.
        String sqlRemove = "DELETE FROM tasks WHERE day = '" + dayString + "'";
        query(sqlRemove);
    }

    /**
     * Inserts all tasks of a day back into the database.
     * Used after editing the tasks on a day.
     * @param dayOneBoolean
     *
     * TODO is this what we need??
     */
    public void putTasksDay(boolean dayOneBoolean) {

        if(dayOneBoolean) { // check if we are putting back the first or the second day
            for (int i = 0; i < dayOne.size(); i++) {
                insertTask(dayOneCal, dayOne.get(i)[0], dayOne.get(i)[1],i);
            }

        } else {
            for (int i = 0; i < dayTwo.size(); i++) {
                insertTask(dayTwoCal, dayTwo.get(i)[0], dayTwo.get(i)[1], i);<commit_msg>changed getTasksDay for broader use<commit_after>package deltadak;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.input.*;
import javafx.scene.layout.GridPane;
import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter;

import java.net.URL;
import java.util.ResourceBundle;

import jdk.nashorn.internal.runtime.ECMAException;

import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.ResourceBundle;

import static java.lang.Integer.min;

public class Controller implements Initializable {
    @FXML ListView<String> day1;
    @FXML ListView<String> day2;
    @FXML GridPane gridpane;

    Connection connection;
    Statement statement;
    int countID = 1;
    ArrayList<String[]> dayOne = new ArrayList<>(); // containing "task", "label"
    ArrayList<String[]> dayTwo = new ArrayList<>();
    Calendar dayOneCal;
    Calendar dayTwoCal;


    /**
     * Initialization method for the controller.
     */
    @FXML public void initialize(URL location, ResourceBundle resourceBundle){

//        deleteTable("tasks");
//        createTable();

        Calendar dayOneCal = Calendar.getInstance();
//        insertTask(dayOneCal, "exam1", "2WA60",1);
//        insertTask(dayOneCal, "exam2", "2WA60",2);
//        insertTask(dayOneCal, "exam3", "2WA30",3);
//        insertTask(dayOneCal, "exam4", "2WA30",4);
//        deleteTasksDay(calendar);

//        getTasksDay(dayOneCal, true, true);
        getTasksDay(dayOneCal, true, false);
        Calendar dayTwoCal = Calendar.getInstance();
        dayTwoCal.add(Calendar.DAY_OF_MONTH,1);
//        insertTask(dayTwoCal, "one", "2WA60",1);
//        insertTask(dayTwoCal, "two", "2WA60",2);
//        insertTask(dayTwoCal, "three", "2WA30",3);
//        insertTask(dayTwoCal, "boom", "2WA30",4);

//        getTasksDay(dayTwoCal, false, true);
        getTasksDay(dayTwoCal, false, false);
//        putTasksDay(true);
//        putTasksDay(false);
        setupGridPane();

    }

    /**
     * database communication below -----------------------------------------------------
     */

    /**
     * inserts a task into the database, given
     * @param dayCal - the date as a Calendar
     * @param task - the task as a string
     * @param label - the label/course (code) as a string
     * @param order - this is the i-th task on this day, as an int
     */
    public void insertTask(Calendar dayCal, String task, String label, int order) {
        getHighestID();

        String dayString = calendarToString(dayCal);

        String sql = "INSERT INTO tasks(id, day, task, label, orderInDay) " +
                    "VALUES (" + countID + ", '" + dayString + "', '" + task + "','" + label + "'," + order + ")";
        countID++;
        query(sql);
    }

    /**
     * Gets all the tasks on a given day, and stores them in dayOne if dayOneBoolean is true.
     * Stores them in dayTwo otherwise.
     *
     * Removes current day from the database when we are going to edit this day.
     *
     * @param dayCal - the date for which to get all the tasks
     * @param dayOneBoolean
     */
    public void getTasksDay(Calendar dayCal, boolean dayOneBoolean, boolean edit) {
        if(dayOneBoolean) {
            dayOneCal = dayCal;
        } else {
            dayTwoCal = dayCal;
        }

        String dayString = calendarToString(dayCal);
        String sql = "SELECT task, label FROM tasks WHERE day = '" + dayString + "' ORDER BY orderInDay";

        setConnection();
        try {
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()) {
                String[] task = {resultSet.getString("task"), resultSet.getString("label")};
                if(dayOneBoolean) {
                    dayOne.add(task);
                } else {
                    dayTwo.add(task);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        if(edit) {
            // remove things from the day we are going to edit.
            String sqlRemove = "DELETE FROM tasks WHERE day = '" + dayString + "'";
            query(sqlRemove);
        }
    }

    /**
     * Inserts all tasks of a day back into the database.
     * Used after editing the tasks on a day.
     * @param dayOneBoolean
     *
     * TODO is this what we need??
     */
    public void putTasksDay(boolean dayOneBoolean) {

        if(dayOneBoolean) { // check if we are putting back the first or the second day
            for (int i = 0; i < dayOne.size(); i++) {
                insertTask(dayOneCal, dayOne.get(i)[0], dayOne.get(i)[1],i);
            }

        } else {
            for (int i = 0; i < dayTwo.size(); i++) {
                insertTask(dayTwoCal, dayTwo.get(i)[0], dayTwo.get(i)[1], i);
{'fraction_non_alphanumeric': 0.1273652867159735, 'fraction_numerical': 0.008836807223129382, 'mean_word_length': 2.345758354755784, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '95897', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2977, 'n_words': 828}