<commit_before># -*- coding:utf-8 -*-

"""
    File: web.py
    Description: going to be a simple web server with realtime data. 
"""

import sys; sys.path.append('helpers')
import threading

import cherrypy


class Home:
    def __init__(self, collector=None):
        self.collector = collector

    def get_html_for_pairs(self, pairs):
        html = ''
        for pair in pairs:
            writer, reader = pair
            for i, item in enumerate([reader, writer]):
                item_type = "reader"
                if i == 1:
                    item_type = "writer"
                html += """
                  <table> 
                  <tr><td>%s</td><td>%s</td></tr>
                  <tr><td>processed</td><td>%s</td></tr>
                  <tr><td>discarded</td><td>%s</td></tr>
                  <tr><td>conf</td><td>%s</td></tr>
                  </table>
                """ % (item_type,
                       item.__class__.__name__, 
                       item.processed, 
                       item.discarded,
                       item.conf)
            html += """
                  <table> 
                  <tr><td>queue maxsize</td><td>%s</td></tr>
                  <tr><td>messages in queue</td><td>%s</td></tr>
                  </table>
            """ % (item.queue.maxsize,
                   item.queue.qsize())
            html += "</br>"
        return html

    def index(self):
        data = {}
        data.update({'number_of_pairs': len(self.collector.pairs) or 'Unavailable'}) 
        data.update({'pairs' : self.get_html_for_pairs(self.collector.pairs) or 'Unavailable'})
        html = """
        <html>
            <head>
            <title>pycollector</title>

            <style type="text/css">
            table {
                border: 1px solid #000}
            </style>

            </head>

            <body>
                <h1>pycollector</h1>
                <p>Collecting units: %(number_of_pairs)s</p>
                <h3><b>Collecting Units</b><h3>
                %(pairs)s
            </body>
        </html>
        """ % data
        return html

    index.exposed = True
<commit_msg>preventing web module to crash when no collector instance is available<commit_after># -*- coding:utf-8 -*-

"""
    File: web.py
    Description: going to be a simple web server with realtime data. 
"""

import sys; sys.path.append('helpers')
import threading

import cherrypy


class Home:
    def __init__(self, collector=None):
        self.collector = collector

    def get_html_for_pairs(self, pairs):
        html = ''
        for pair in pairs:
            writer, reader = pair
            for i, item in enumerate([reader, writer]):
                item_type = "reader"
                if i == 1:
                    item_type = "writer"
                html += """
                  <table> 
                  <tr><td>%s</td><td>%s</td></tr>
                  <tr><td>processed</td><td>%s</td></tr>
                  <tr><td>discarded</td><td>%s</td></tr>
                  <tr><td>conf</td><td>%s</td></tr>
                  </table>
                """ % (item_type,
                       item.__class__.__name__, 
                       item.processed, 
                       item.discarded,
                       item.conf)
            html += """
                  <table> 
                  <tr><td>queue maxsize</td><td>%s</td></tr>
                  <tr><td>messages in queue</td><td>%s</td></tr>
                  </table>
            """ % (item.queue.maxsize,
                   item.queue.qsize())
            html += "</br>"
        return html

    def index(self):
        if not self.collector or \
            not hasattr(self.collector, 'pairs'):
            return "Unavailable"
        data = {}
        data.update({'number_of_pairs': len(self.collector.pairs) or 'Unavailable'}) 
        data.update({'pairs' : self.get_html_for_pairs(self.collector.pairs) or 'Unavailable'})
        html = """
        <html>
            <head>
            <title>pycollector</title>

            <style type="text/css">
            table {
                border: 1px solid #000}
            </style>

            </head>

            <body>
                <h1>pycollector</h1>
                <p>Collecting units: %(number_of_pairs)s</p>
                <h3><b>Collecting Units</b><h3>
                %(pairs)s
            </body>
        </html>
        """ % data
        return html

    index.exposed = True

{'fraction_non_alphanumeric': 0.14431843451189683, 'fraction_numerical': 0.004447409384033801, 'mean_word_length': 1.2948979591836736, 'pattern_counts': {'":': 0, '<': 121, '<?xml version=': 0, '>': 121, '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': '42384', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1283, 'n_words': 255}