<commit_before>/*
 Copyright 2016 <NAME>

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
package com.github.livepvrdata.monitors.espn.json

import com.github.livepvrdata.AppRuntime
import com.github.livepvrdata.common.data.Event

import groovy.json.JsonSlurper
import net.sf.ehcache.Element

class CFB extends Monitor {
    private static final String SPORT = 'football'
    private static final String LEAGUE = 'college-football'
    private static final String CONFERENCES_URL = "http://site.api.espn.com/apis/site/v2/sports/$SPORT/$LEAGUE/scoreboard/conferences";

    static String getNormalizedTitle() { 'College Football' }
    static Event[] getEventsForDate(long date) throws IOException {	Monitor.getEventsForDate(SPORT, LEAGUE, date, fetchGroupIds()) }

    public static String fetchGroupIds() {
        String key = String.format("espnjson_%s_%s_groups", SPORT, LEAGUE)
        def groups = AppRuntime.instance.statusCache.get(key)

        if(groups == null) {
            String data = new URL(CONFERENCES_URL).text
            def json = new JsonSlurper().parseText(data)

            String groupData = json.conferences.collect {
                it.groupId
            }.join(",")

            def element = new Element(key, groupData)
            element.timeToLive = 3600 * 24 * 7 //one week
            AppRuntime.instance.statusCache.put(element)

            return groupData
        } else {
            return groups.objectValue<commit_msg>Fix College Football group handling<commit_after>/*
 Copyright 2016 Battams, Derek

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
package com.github.livepvrdata.monitors.espn.json

import com.github.livepvrdata.AppRuntime
import com.github.livepvrdata.common.data.Event

import groovy.json.JsonSlurper
import net.sf.ehcache.Element

class CFB extends Monitor {
    private static final String SPORT = 'football'
    private static final String LEAGUE = 'college-football'
    private static final String CONFERENCES_URL = "http://site.api.espn.com/apis/site/v2/sports/$SPORT/$LEAGUE/scoreboard/conferences";

    static String getNormalizedTitle() { 'College Football' }
    static Event[] getEventsForDate(long date) throws IOException {	Monitor.getEventsForDate(SPORT, LEAGUE, date, fetchGroupIds()) }

    public static String fetchGroupIds() {
        String key = String.format("espnjson_%s_%s_groups_v2", SPORT, LEAGUE)
        def groups = AppRuntime.instance.statusCache.get(key)

        if(groups == null) {
            String data = new URL(CONFERENCES_URL).text
            def json = new JsonSlurper().parseText(data)

            String groupData = json.conferences.findResults {
                //Don't include "sub-groups", only groups with no parent
                //  The ESPN feed doesn't return the status appropriately when sub-groups
                //  and their parents are both in the request
                it.parentGroupId  ?  null : it.groupId
            }.join(",")

            def element = new Element(key, groupData)
            element.timeToLive = 3600 * 24 * 7 //one week
            AppRuntime.instance.statusCache.put(element)

            return groupData
        } else {
            return groups.objectValue
{'fraction_non_alphanumeric': 0.08142311365807067, 'fraction_numerical': 0.007879656160458453, 'mean_word_length': 3.086829268292683, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1116576', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1130, 'n_words': 378}