<commit_before>/*
 *******************************************************************************
 * Copyright (c) 2014 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************
*/
package com.whizzosoftware.hobson.scheduler;

import com.whizzosoftware.hobson.api.event.EventHandler;
import com.whizzosoftware.hobson.api.event.hub.HubConfigurationUpdateEvent;
import com.whizzosoftware.hobson.api.hub.HubConfigurationClass;
import com.whizzosoftware.hobson.api.plugin.AbstractHobsonPlugin;
import com.whizzosoftware.hobson.api.plugin.PluginStatus;
import com.whizzosoftware.hobson.api.plugin.PluginType;
import com.whizzosoftware.hobson.api.property.PropertyContainer;
import com.whizzosoftware.hobson.api.property.TypedProperty;
import com.whizzosoftware.hobson.scheduler.condition.ScheduleConditionClass;
import com.whizzosoftware.hobson.scheduler.queue.LocalTaskQueue;
import com.whizzosoftware.hobson.scheduler.ical.ICalTaskProvider;
import com.whizzosoftware.hobson.scheduler.util.SolarHelper;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Hobson plugin that provides scheduling capabilities.
 *
 * @author <NAME>
 */
public class SchedulerPlugin extends AbstractHobsonPlugin implements DayResetListener {
    private static final Logger logger = LoggerFactory.getLogger(SchedulerPlugin.class);

    private static final String SUNRISE = "sunrise";
    private static final String SUNSET = "sunset";

    private Double latitude;
    private Double longitude;

    public SchedulerPlugin(String pluginId, String version, String description) {
        super(pluginId, version, description);
    }

    @Override
    public void onStartup(PropertyContainer config) {
        // get latitude and longitude
        latitude = getHubLatitude();
        longitude = getHubLongitude();

        // create an ical task provider
        ICalTaskProvider taskProvider = new ICalTaskProvider(getContext(), latitude, longitude);
        taskProvider.setScheduleExecutor(new LocalTaskQueue(getTaskManager()));
        taskProvider.setTaskManager(getTaskManager());
        taskProvider.setDayResetListener(this);
        taskProvider.start();
        setTaskProvider(taskProvider);

        // publish conditions that this plugin can trigger
        publishTaskConditionClass(new ScheduleConditionClass(getContext()));

        // set the initial sunrise and sunset
        String sunrise = null;
        String sunset = null;
        Long lastUpdate = null;
        String ss[] = SolarHelper.getSunriseSunset(latitude, longitude, DateTimeZone.getDefault(), System.currentTimeMillis());
        if (ss != null) {
            sunrise = ss[0];
            sunset = ss[1];
            lastUpdate = System.currentTimeMillis();
        }

        // publish sunrise/sunset global variables
        Map<String,Object> vars = new HashMap<>();
        vars.put(SUNRISE, sunrise);
        vars.put(SUNSET, sunset);
        setGlobalVariables(vars, lastUpdate != null ? lastUpdate : System.currentTimeMillis());

        // set the plugin to running status
        setStatus(new PluginStatus(PluginStatus.Code.RUNNING));
    }

    @Override
    public void onShutdown() {
        ((ICalTaskProvider)getTaskProvider()).stop();
    }

    @Override
    protected TypedProperty[] getConfigurationPropertyTypes() {
        return null;
    }

    @Override
    public PluginType getType() {
        return PluginType.CORE;
    }

    @Override<commit_msg>Refactored onPluginConfigurationUpdate to be specific to its plugin and now takes a config object argument.<commit_after>/*
 *******************************************************************************
 * Copyright (c) 2014 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************
*/
package com.whizzosoftware.hobson.scheduler;

import com.whizzosoftware.hobson.api.event.EventHandler;
import com.whizzosoftware.hobson.api.event.hub.HubConfigurationUpdateEvent;
import com.whizzosoftware.hobson.api.hub.HubConfigurationClass;
import com.whizzosoftware.hobson.api.plugin.AbstractHobsonPlugin;
import com.whizzosoftware.hobson.api.plugin.PluginStatus;
import com.whizzosoftware.hobson.api.plugin.PluginType;
import com.whizzosoftware.hobson.api.property.PropertyContainer;
import com.whizzosoftware.hobson.api.property.TypedProperty;
import com.whizzosoftware.hobson.scheduler.condition.ScheduleConditionClass;
import com.whizzosoftware.hobson.scheduler.queue.LocalTaskQueue;
import com.whizzosoftware.hobson.scheduler.ical.ICalTaskProvider;
import com.whizzosoftware.hobson.scheduler.util.SolarHelper;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Hobson plugin that provides scheduling capabilities.
 *
 * @author <NAME>
 */
public class SchedulerPlugin extends AbstractHobsonPlugin implements DayResetListener {
    private static final Logger logger = LoggerFactory.getLogger(SchedulerPlugin.class);

    private static final String SUNRISE = "sunrise";
    private static final String SUNSET = "sunset";

    private Double latitude;
    private Double longitude;

    public SchedulerPlugin(String pluginId, String version, String description) {
        super(pluginId, version, description);
    }

    @Override
    public void onStartup(PropertyContainer config) {
        // get latitude and longitude
        latitude = getHubLatitude();
        longitude = getHubLongitude();

        // create an ical task provider
        ICalTaskProvider taskProvider = new ICalTaskProvider(getContext(), latitude, longitude);
        taskProvider.setScheduleExecutor(new LocalTaskQueue(getTaskManager()));
        taskProvider.setTaskManager(getTaskManager());
        taskProvider.setDayResetListener(this);
        taskProvider.start();
        setTaskProvider(taskProvider);

        // publish conditions that this plugin can trigger
        publishTaskConditionClass(new ScheduleConditionClass(getContext()));

        // set the initial sunrise and sunset
        String sunrise = null;
        String sunset = null;
        Long lastUpdate = null;
        String ss[] = SolarHelper.getSunriseSunset(latitude, longitude, DateTimeZone.getDefault(), System.currentTimeMillis());
        if (ss != null) {
            sunrise = ss[0];
            sunset = ss[1];
            lastUpdate = System.currentTimeMillis();
        }

        // publish sunrise/sunset global variables
        Map<String,Object> vars = new HashMap<>();
        vars.put(SUNRISE, sunrise);
        vars.put(SUNSET, sunset);
        setGlobalVariables(vars, lastUpdate != null ? lastUpdate : System.currentTimeMillis());

        // set the plugin to running status
        setStatus(new PluginStatus(PluginStatus.Code.RUNNING));
    }

    @Override
    public void onShutdown() {
        ((ICalTaskProvider)getTaskProvider()).stop();
    }

    @Override
    public void onPluginConfigurationUpdate(PropertyContainer config) {
    }

    @Override
    protected TypedProperty[] getConfigurationPropertyTypes() {
        return null;
    }

    @Override
    public PluginType getType() {
        return PluginType.CORE;
    }

    @Override
{'fraction_non_alphanumeric': 0.1271023237899602, 'fraction_numerical': 0.0030812684555141866, 'mean_word_length': 3.8626716604244695, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1464861', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2028, 'n_words': 482}