<commit_before>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import * as moment from "moment";
import {Chart} from 'react-charts';

import * as data from "data";

import { _ } from 'translate';
import { Modal, openModal } from "Modal";

declare let swal;

interface Events {
}

interface JosekiStatsModalProperties {
    daily_page_visits: Array<{date: string; pageVisits: number;
        explorePageVisits: number; playPageVisits: number; guestPageVisits: number; }>;
}

function StatsChart(props: JosekiStatsModalProperties) {
    const stats_data = React.useMemo(() => (
        [
            {
                label: 'Total Page Visits',
                data: props.daily_page_visits.map(day => ({x: new Date(day.date).setHours(0, 0, 0, 0), y: day.pageVisits}))
            },
            {
                label: 'Explore Page Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.explorePageVisits])
            },
            {
                label: 'Play Mode Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.playPageVisits])
            },
            {
                label: 'Guest Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.guestPageVisits])
            }
        ]), [props]);

    const axes =
        [
            { primary: true, type: 'time', position: 'bottom' },
            { type: 'linear', position: 'left' }
        ];

    const series = {
        showPoints: false
    };

    // Accessible TBD - assumes dark for now
    const label_colour = data.get("theme") === "light" ? false : true;

    return (
        <Chart
            data={stats_data} axes={axes} series={series} tooltip dark={label_colour}
        />
    );
}

export class JosekiStatsModal extends Modal<Events, JosekiStatsModalProperties, any> {

    render() {
        const start_graph = moment("2020-01-15");  // before this time the data is dodgy
        const today = moment().startOf('day');

        const daily_page_visits = this.props.daily_page_visits
            .filter((day) => ((moment(day.date) > start_graph) && (moment(day.date) < today)))
            // strip out tiny days, which theoretically shouldn't be there in the first place
            // (I think they get there when two people simultaneously click on a position in the first visit of a day)
            .filter((day) => (day.pageVisits > 10));

        return (<commit_msg>show smaller stats days<commit_after>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import * as moment from "moment";
import {Chart} from 'react-charts';

import * as data from "data";

import { _ } from 'translate';
import { Modal, openModal } from "Modal";

declare let swal;

interface Events {
}

interface JosekiStatsModalProperties {
    daily_page_visits: Array<{date: string; pageVisits: number;
        explorePageVisits: number; playPageVisits: number; guestPageVisits: number; }>;
}

function StatsChart(props: JosekiStatsModalProperties) {
    const stats_data = React.useMemo(() => (
        [
            {
                label: 'Total Page Visits',
                data: props.daily_page_visits.map(day => ({x: new Date(day.date).setHours(0, 0, 0, 0), y: day.pageVisits}))
            },
            {
                label: 'Explore Page Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.explorePageVisits])
            },
            {
                label: 'Play Mode Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.playPageVisits])
            },
            {
                label: 'Guest Visits',
                data: props.daily_page_visits.map(day => [new Date(day.date).setHours(0, 0, 0, 0), day.guestPageVisits])
            }
        ]), [props]);

    const axes =
        [
            { primary: true, type: 'time', position: 'bottom' },
            { type: 'linear', position: 'left' }
        ];

    const series = {
        showPoints: false
    };

    // Accessible TBD - assumes dark for now
    const label_colour = data.get("theme") === "light" ? false : true;

    return (
        <Chart
            data={stats_data} axes={axes} series={series} tooltip dark={label_colour}
        />
    );
}

export class JosekiStatsModal extends Modal<Events, JosekiStatsModalProperties, any> {

    render() {
        const start_graph = moment("2020-01-15");  // before this time the data is dodgy
        const today = moment().startOf('day');

        const daily_page_visits = this.props.daily_page_visits
            .filter((day) => ((moment(day.date) > start_graph) && (moment(day.date) < today)))
            // strip out tiny days, which theoretically shouldn't be there in the first place
            // (I think they get there when two people simultaneously click on a position in the first visit of a day)
            .filter((day) => (day.pageVisits > 2));

        return (
{'fraction_non_alphanumeric': 0.1140040055461408, 'fraction_numerical': 0.01063010321984286, 'mean_word_length': 2.494079655543595, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '974774', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1832, 'n_words': 621}