<commit_before>#include "alarm_mgr.h"
#include <iostream>
#include <sqlite/execute.hpp>
#include <sqlite/query.hpp>

AlarmMgr::AlarmMgr() : AlarmMgr::AlarmMgr("alarm.db") {}
AlarmMgr::AlarmMgr(std::string alarmdb_name) : alarmdb(alarmdb_name)
{
    try
    {
        sqlite::execute(alarmdb, "CREATE TABLE alarms"
                "("
                " id INTEGER PRIMARY KEY,"
                " series_name TEXT,"
                " dow INT,"
                " hr INT,"
                " min INT,"
                " start_date DATE,"
                " stop_date DATE,"
                " last_run DATETIME"
                ");", true);
    }
    catch(std::exception const & e)
    {
        std::cerr << e.what() << std::endl;
    }
}
AlarmMgr::~AlarmMgr() {}

void AlarmMgr::check_alarms()
{
    // Get the time.
    time_t rawtime;
    time(&rawtime);
    struct tm* now = localtime (&rawtime);

    sqlite::query q(alarmdb, "SELECT * FROM alarms" // Find an alarm that
            " WHERE start_date<=strftime('%s', 'now')" // Has started
            " AND stop_date>=strftime('%s', 'now', 'start of day', '+1 day')" // Has not expired
            " AND last_run<=strftime('%s','now', '-1 minute');"); // and has not been run.
    boost::shared_ptr<sqlite::result> result = q.get_result();
    while(result->next_row())
    {
        if( now->tm_wday == result->get_int((int)col_names::dow) &&
            now->tm_hour == result->get_int((int)col_names::hr)  &&
            now->tm_min  == result->get_int((int)col_names::min)
          )
        {
            // Activate alarm.
            m_signal_alarm_activated.emit(result->get_string((int)col_names::series_name));<commit_msg>Added option for daily alarm.<commit_after>#include "alarm_mgr.h"
#include <iostream>
#include <sqlite/execute.hpp>
#include <sqlite/query.hpp>

AlarmMgr::AlarmMgr() : AlarmMgr::AlarmMgr("alarm.db") {}
AlarmMgr::AlarmMgr(std::string alarmdb_name) : alarmdb(alarmdb_name)
{
    try
    {
        sqlite::execute(alarmdb, "CREATE TABLE alarms"
                "("
                " id INTEGER PRIMARY KEY,"
                " series_name TEXT,"
                " dow INT,"
                " hr INT,"
                " min INT,"
                " start_date DATE,"
                " stop_date DATE,"
                " last_run DATETIME"
                ");", true);
    }
    catch(std::exception const & e)
    {
        std::cerr << e.what() << std::endl;
    }
}
AlarmMgr::~AlarmMgr() {}

void AlarmMgr::check_alarms()
{
    // Get the time.
    time_t rawtime;
    time(&rawtime);
    struct tm* now = localtime (&rawtime);

    sqlite::query q(alarmdb, "SELECT * FROM alarms" // Find an alarm that
            " WHERE start_date<=strftime('%s', 'now')" // Has started
            " AND stop_date>=strftime('%s', 'now', 'start of day', '+1 day')" // Has not expired
            " AND last_run<=strftime('%s','now', '-1 minute');"); // and has not been run.
    boost::shared_ptr<sqlite::result> result = q.get_result();
    while(result->next_row())
    {
        if( (result->get_int((int)col_names::dow) == now->tm_wday || // If the alarm is for this day
             result->get_int((int)col_names::dow) == -1) && // Or every day
             result->get_int((int)col_names::hr)  == now->tm_hour  && // and for this hour
             result->get_int((int)col_names::min) == now->tm_min) // and for this minute
        {
            // Activate alarm.
            m_signal_alarm_activated.emit(result->get_string((int)col_names::series_name));
{'fraction_non_alphanumeric': 0.16147308781869688, 'fraction_numerical': 0.00141643059490085, 'mean_word_length': 2.2041742286751362, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 30, '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': '2230506', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1159, 'n_words': 233}