<commit_before>import React, {Component} from 'react';
import axios from 'axios';

class Worksheet extends Component {
    constructor(props) {
        super(props);
        this.state = {
            sheet: require("../../json/test.json"),
            description: false,
            id: props.id,
            exercises: [],
        };
    }

    componentDidMount() {
        this.getWorksheet();
    }

    getWorksheet() {
        let _this = this;
        axios.get('http://localhost:3000/users/' + _this.state.id + '/worksheet')
            .then(function (response) {
                console.log(response);
                _this.setState({sheet: response.data});
            })
            .catch(function (error) {
                console.log(error);
                //window.alert(error);
            });
    }

    send(week, day, time, done) {
        console.log("sending data...");

        let _this = this;
        axios.post('http://localhost:3000/users/' + _this.state.id + '/UploadWorkout ',
            {week:week,day:day,time:time,done:done,exercises:_this.state.exercises})
            .then(function (response) {
                console.log(response);
                //window.alert("Workout sent!");
                _this.getWorksheet();
            })
            .catch(function (error) {
                console.log(error);
                //window.alert(error);
            });
    }

    handleInputChange(exerciseIndex, event) {
        const target = event.target;
        const value = target.type === 'checkbox' ? target.checked : target.value;
        const name = target.name;

        let exercises = this.state.exercises;
        let jsonData = exercises[exerciseIndex] !== undefined ? exercises[exerciseIndex] : {};
        jsonData[name] = value;
        exercises[exerciseIndex] = jsonData;

        this.setState({
            exercises: exercises,
        });
    }

    renderExercise(exercise, index) {<commit_msg>[frontend] skip sending, ect.<commit_after>import React, {Component} from 'react';
import axios from 'axios';

class Worksheet extends Component {
    constructor(props) {
        super(props);
        this.state = {
            sheet: require("../../json/test.json"),
            description: false,
            id: props.id,
            exercises: [],
            skippedExercises: [],
        };
    }

    componentDidMount() {
        this.getWorksheet();

        let _this = this;
        let firstUndone = true;
        let BreakException = {};
        try {
            this.state.sheet.weeks.forEach(function (week) {
                week.forEach(function (day) {
                    day.workouts.forEach(function (workout) {
                        if (firstUndone && !workout.done) {
                            _this.setState({exercises: workout.exercises, skippedExercises: workout.exercises});
                            firstUndone = false;
                            throw BreakException;
                        }
                    });
                });
            });
        } catch (e) {
            if (e !== BreakException) console.log(e);
        }
    }

    getWorksheet() {
        let _this = this;
        axios.get('http://localhost:3000/users/' + _this.state.id + '/worksheet')
            .then(function (response) {
                console.log(response);
                _this.setState({sheet: response.data});
            })
            .catch(function (error) {
                console.log(error);
                //window.alert(error);
            });
    }

    postExercises(week, day, time, exercises) {
        let _this = this;
        axios.post('http://localhost:3000/users/' + _this.state.id + '/UploadWorkout ',
            {week: week, day: day, time: time, done: done, exercises: exercises})
            .then(function (response) {
                console.log(response);
                //window.alert("Workout sent!");
                _this.getWorksheet();
            })
            .catch(function (error) {
                console.log(error);
                //window.alert(error);
            });
    }

    send(week, day, time, done) {
        console.log("sending data...");
        if (done === "skip") {
            this.postExercises(week, day, time, this.state.skippedExercises);
        } else {
            this.postExercises(week, day, time, this.state.exercises);
        }
    }

    handleInputChange(exerciseIndex, event) {
        const target = event.target;
        const value = target.type === 'checkbox' ? target.checked : target.value;
        const name = target.name;

        let exercises = this.state.exercises;
        let jsonData = exercises[exerciseIndex] !== undefined ? exercises[exerciseIndex] : {};
        jsonData[name] = value;
        exercises[exerciseIndex] = jsonData;

        this.setState({
            exercises: exercises,
        });
    }

    renderExercise(exercise, index) {
{'fraction_non_alphanumeric': 0.13215948188625784, 'fraction_numerical': 0.0032382108884841127, 'mean_word_length': 1.6245353159851301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2478676', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1318, 'n_words': 251}