<commit_before>use uuid::Uuid;
use std::collections::BTreeMap;
use std::fmt::Write;
use std::rc::Rc;

use conditions::Conditions;
use message::{Message};
use state::State;
use timer::TimerEvent;
use context::base::BaseContext;
use context::event::EventHandler;
use dispatcher::request::{Request, InternalRequest};

pub struct MapContext {
    base: BaseContext,
    map: BTreeMap<String, State>,
    format_buffer: String
}

impl MapContext {
    pub fn new(uuid: Uuid, conditions: Conditions) -> MapContext {
        MapContext {
            base: BaseContext::new(uuid, conditions),
            map: BTreeMap::new(),
            format_buffer: String::new()
        }
    }

    pub fn on_event(&mut self, event: InternalRequest) {
        if let Request::Message(event) = event {
            self.on_message(event);
        }
    }

    pub fn on_timer(&mut self, event: &TimerEvent) {
        for (_, mut state) in self.map.iter_mut() {
            self.base.on_timer(event, &mut state);

        }
        self.remove_closed_states();
    }

    fn get_closed_state_ids(&self) -> Vec<String> {
        self.map.iter().filter_map(|(id, state)| {
            if !state.is_open() {
                Some(id.clone())
            } else {
                None
            }
        }).collect::<Vec<String>>()<commit_msg>MapContext: call on_message() when a Message request is received<commit_after>use uuid::Uuid;
use std::collections::BTreeMap;
use std::fmt::Write;
use std::rc::Rc;

use conditions::Conditions;
use message::{Message};
use state::State;
use timer::TimerEvent;
use context::base::BaseContext;
use context::event::EventHandler;
use dispatcher::request::{Request, InternalRequest};

pub struct MapContext {
    base: BaseContext,
    map: BTreeMap<String, State>,
    format_buffer: String
}

impl MapContext {
    pub fn new(uuid: Uuid, conditions: Conditions) -> MapContext {
        MapContext {
            base: BaseContext::new(uuid, conditions),
            map: BTreeMap::new(),
            format_buffer: String::new()
        }
    }

    pub fn on_event(&mut self, event: InternalRequest) {
        match event {
            Request::Timer(event) => {
                self.on_timer(&event)
            },
            Request::Message(message) => {
                self.on_message(message)
            },
            _ => {}
        }
    }

    pub fn on_timer(&mut self, event: &TimerEvent) {
        for (_, mut state) in self.map.iter_mut() {
            self.base.on_timer(event, &mut state);

        }
        self.remove_closed_states();
    }

    fn get_closed_state_ids(&self) -> Vec<String> {
        self.map.iter().filter_map(|(id, state)| {
            if !state.is_open() {
                Some(id.clone())
            } else {
                None
            }
        }).collect::<Vec<String>>()
{'fraction_non_alphanumeric': 0.13702007749207468, 'fraction_numerical': 0.0, 'mean_word_length': 2.368920521945433, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '774972', 'n_tokens_mistral': 849, 'n_tokens_neox': 842, 'n_words': 182}