<commit_before>package edu.yalestc.yalepublic.Events;

import android.content.Context;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;

import edu.yalestc.yalepublic.R;

/**
 * Created by <NAME> on 11/11/14.
 * <p/>
 * Class used to parse given JSON for the EventsCalendarEventList usage. Parses the given JSON into
 * a ListArray of a class holding the place, date and title of the event. Can be queried from outside
 * for events on a given day
 */
public class EventsParseForDateWithinCategory {

    private ArrayList<event> validEvents;
    private int mMonth;
    private int mYear;
    private int mSearchedCategoryNumber;
    private int numberOfEvents;
    //for use in events class to parse the category of an event that will be used in the EventsCalendarEventList class
    //for deciding on the color of the blobs
    final private String[] availableCategories;

    //Context passed in for access to resources
    public EventsParseForDateWithinCategory(String rawData, int month, int year, Context context, int searchedCategoryNumber) {
        mSearchedCategoryNumber = searchedCategoryNumber;
        availableCategories = context.getResources().getStringArray(R.array.events_category_names_json);
        setNewEvents(rawData, month, year);
    }

    //parse the data pulled for validEvents. A validEvent is one that starts over the course of
    //given month
    public void setNewEvents(String rawData, int month, int year) {
        //because the calendar gives numbers 0-11
        mMonth = month + 1;
        mYear = year;
        numberOfEvents = 0;
        JSONArray events;
        JSONObject mAllData;
        validEvents = new ArrayList<event>();
        try {
            //substring necessary - JSON option was implemented by Yale poorly and returns javascript.
            //have to get rid of variable definition
            mAllData = new JSONObject(rawData.substring(24));
            events = mAllData.getJSONObject("bwEventList")
                    .getJSONArray("events");
            for (int i = 0; i < events.length(); i++) {
                if (isValidEvent(events.getJSONObject(i))) {
                    numberOfEvents++;
                    validEvents.add(new event(events.getJSONObject(i)));
                }
            }
        } catch (JSONException e) {
            Log.e("EventsParseForCategory", "setNewEvents JSON error");
        }
    }

    public int getNumberOfEvents(){
        return numberOfEvents;
    }

    //returns an ArrayList of String[] with the information about events on a given date.
    //The structure of every event is:
    //event[0] = title
    //event[1] = start time
    //event[2] = end time
    //event[3] = place
    //event[4] = dateDescription
    //event[5] = description
    //event[6] = categoryNumber
    //event[7] = date
    public ArrayList<String[]> getEventsOnGivenDate(String date) {
        ArrayList<String[]> givenEvents = new ArrayList<String[]>();
        for (int i = 0; i < validEvents.size(); i++) {
            if (validEvents.get(i).getDate().equals(date)) {
                givenEvents.add(validEvents.get(i).getInfo());<commit_msg>return .size() not counted size<commit_after>package edu.yalestc.yalepublic.Events;

import android.content.Context;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;

import edu.yalestc.yalepublic.R;

/**
 * Created by <NAME> on 11/11/14.
 * <p/>
 * Class used to parse given JSON for the EventsCalendarEventList usage. Parses the given JSON into
 * a ListArray of a class holding the place, date and title of the event. Can be queried from outside
 * for events on a given day
 */
public class EventsParseForDateWithinCategory {

    private ArrayList<event> validEvents;
    private int mMonth;
    private int mYear;
    private int mSearchedCategoryNumber;
    //for use in events class to parse the category of an event that will be used in the EventsCalendarEventList class
    //for deciding on the color of the blobs
    final private String[] availableCategories;

    //Context passed in for access to resources
    public EventsParseForDateWithinCategory(String rawData, int month, int year, Context context, int searchedCategoryNumber) {
        mSearchedCategoryNumber = searchedCategoryNumber;
        availableCategories = context.getResources().getStringArray(R.array.events_category_names_json);
        setNewEvents(rawData, month, year);
    }

    //parse the data pulled for validEvents. A validEvent is one that starts over the course of
    //given month
    public void setNewEvents(String rawData, int month, int year) {
        //because the calendar gives numbers 0-11
        mMonth = month + 1;
        mYear = year;
        JSONArray events;
        JSONObject mAllData;
        validEvents = new ArrayList<event>();
        try {
            //substring necessary - JSON option was implemented by Yale poorly and returns javascript.
            //have to get rid of variable definition
            mAllData = new JSONObject(rawData.substring(24));
            events = mAllData.getJSONObject("bwEventList")
                    .getJSONArray("events");
            for (int i = 0; i < events.length(); i++) {
                if (isValidEvent(events.getJSONObject(i))) {
                    validEvents.add(new event(events.getJSONObject(i)));
                }
            }
        } catch (JSONException e) {
            Log.e("EventsParseForCategory", "setNewEvents JSON error");
        }
    }

    public int getNumberOfEvents(){
        return validEvents.size();
    }

    //returns an ArrayList of String[] with the information about events on a given date.
    //The structure of every event is:
    //event[0] = title
    //event[1] = start time
    //event[2] = end time
    //event[3] = place
    //event[4] = dateDescription
    //event[5] = description
    //event[6] = categoryNumber
    //event[7] = date
    public ArrayList<String[]> getEventsOnGivenDate(String date) {
        ArrayList<String[]> givenEvents = new ArrayList<String[]>();
        for (int i = 0; i < validEvents.size(); i++) {
            if (validEvents.get(i).getDate().equals(date)) {
                givenEvents.add(validEvents.get(i).getInfo());
{'fraction_non_alphanumeric': 0.0944686140459913, 'fraction_numerical': 0.006991920447482909, 'mean_word_length': 2.703682393555811, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '4741959', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1717, 'n_words': 579}