<commit_before># -*- coding: utf-8 -*-
"""
Helper functions used in views.
"""

import csv
from json import dumps
from functools import wraps
from datetime import datetime
from lxml import etree
from flask import Response
from presence_analyzer.main import app
import time
import threading

import logging
log = logging.getLogger(__name__)  # pylint: disable-msg=C0103

CACHE = {}
CACHE_LOCKER = threading.Lock()


def cache(duration):
    def _cache(fun):
        def __cache(*args, **kwargs):
            with CACHE_LOCKER:
                if (fun.__name__ not in CACHE or
                   time.time()-CACHE[fun.__name__]['time'] > duration):
                    CACHE[fun.__name__] = {
                        'data': fun(*args, **kwargs),
                        'time': time.time()
                    }
                return CACHE[fun.__name__]['data']
        return __cache
    return _cache


def get_data_xml():
    """
    Parses data from XML file (server and users info).
    """
    xml_file = etree.parse(app.config['DATA_XML']).getroot()
    server = {<commit_msg>[1856] Fixed some pylint errors<commit_after># -*- coding: utf-8 -*-
"""
Helper functions used in views.
"""

import csv
from json import dumps
from functools import wraps
from datetime import datetime
from lxml import etree
from flask import Response
from presence_analyzer.main import app
from time import time as cur_time
import threading

import logging
log = logging.getLogger(__name__)  # pylint: disable-msg=C0103

CACHE = {}
CACHE_LOCKER = threading.Lock()


def cache(duration):
    def _cache(fun):
        def __cache():
            with CACHE_LOCKER:
                if (fun.__name__ not in CACHE or
                   cur_time()-CACHE[fun.__name__]['time'] > duration):
                    CACHE[fun.__name__] = {
                        'data': fun(),
                        'time': cur_time()
                    }
                return CACHE[fun.__name__]['data']
        return __cache
    return _cache


def get_data_xml():
    """
    Parses data from XML file (server and users info).
    """
    xml_file = etree.parse(app.config['DATA_XML']).getroot()
    server = {
{'fraction_non_alphanumeric': 0.10671573137074516, 'fraction_numerical': 0.006439742410303588, 'mean_word_length': 2.260869565217391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '2738291', 'n_tokens_mistral': 645, 'n_tokens_neox': 607, 'n_words': 186}