<commit_before>require('rootpath')();
import express = require('express')
import events = require("events");
import ClientConnection = require('./ClientConnection');
import MessageBus = require('../bus/MessageBus');
import fs = require('fs');
import path = require('path');
import utils = require('../helpers/Utils');
import GeoJSON = require("../helpers/GeoJSON");

export interface IDynamicLayer {
    connection?: ClientConnection.ConnectionManager;
    getLayer(req: express.Request, res: express.Response);
    getDataSource(req: express.Request, res: express.Response);
    addFeature?: (feature: any) => void;
    updateFeature?: (ft: GeoJSON.IFeature, client?: string, notify?: boolean) => void;
    updateLog?: (featureId: string, msgBody: IMessageBody, client?: string, notify?: boolean) => void;
    layerId: string;
    start();
    on?: (event: string, listener: Function) => events.EventEmitter;
}

export interface IPropertyUpdate {
    /** Timestamp */
    ts: number;
    /** Property key */
    prop: string;
    /** Property value */
    value: any;
}

export interface IMessageBody {
    featureId: string;
    logs?: { [prop: string]: IPropertyUpdate[] };
}

export class DynamicLayer extends events.EventEmitter implements IDynamicLayer {
    private file: string;
    /**
     * Working copy of geojson file
     */
    public geojson: any;
    public server: express.Express;
    public messageBus: MessageBus.MessageBusService;
    public connection: ClientConnection.ConnectionManager;
    public startDate: number;

    constructor(public layerId: string, file: string, server: express.Express, messageBus: MessageBus.MessageBusService, connection: ClientConnection.ConnectionManager) {
        super();
        this.geojson = { features: [] };
        this.file = file;
        this.server = server;
        this.messageBus = messageBus;
        this.connection = connection;
    }

    public getLayer(req: express.Request, res: express.Response) {
        res.send(JSON.stringify(this.geojson));
    }

    public OpenFile() {
        fs.readFile(this.file, 'utf8', (err, data) => {
            if (!err) {
                this.geojson = JSON.parse(data);
                this.geojson.features.forEach((f: csComp.Services.IFeature) => {
                    this.initFeature(f);
                });
            }
            else {
                console.log('error:' + this.file);<commit_msg>Updated interface to dynamic geojson data.<commit_after>require('rootpath')();
import express = require('express')
import events = require("events");
import ClientConnection = require('./ClientConnection');
import MessageBus = require('../bus/MessageBus');
import fs = require('fs');
import path = require('path');
import utils = require('../helpers/Utils');
import GeoJSON = require("../helpers/GeoJSON");

export interface IDynamicLayer {
    geojson?: GeoJSON.IGeoJson;
    connection?: ClientConnection.ConnectionManager;
    getLayer(req: express.Request, res: express.Response);
    getDataSource(req: express.Request, res: express.Response);
    addFeature?: (feature: any) => void;
    updateFeature?: (ft: GeoJSON.IFeature, client?: string, notify?: boolean) => void;
    updateLog?: (featureId: string, msgBody: IMessageBody, client?: string, notify?: boolean) => void;
    layerId: string;
    start();
    on?: (event: string, listener: Function) => events.EventEmitter;
}

export interface IPropertyUpdate {
    /** Timestamp */
    ts: number;
    /** Property key */
    prop: string;
    /** Property value */
    value: any;
}

export interface IMessageBody {
    featureId: string;
    logs?: { [prop: string]: IPropertyUpdate[] };
}

export class DynamicLayer extends events.EventEmitter implements IDynamicLayer {
    private file: string;
    /**
     * Working copy of geojson file
     */
    public geojson: GeoJSON.IGeoJson;
    public server: express.Express;
    public messageBus: MessageBus.MessageBusService;
    public connection: ClientConnection.ConnectionManager;
    public startDate: number;

    constructor(public layerId: string, file: string, server: express.Express, messageBus: MessageBus.MessageBusService, connection: ClientConnection.ConnectionManager) {
        super();
        this.geojson = { features: [] };
        this.file = file;
        this.server = server;
        this.messageBus = messageBus;
        this.connection = connection;
    }

    public getLayer(req: express.Request, res: express.Response) {
        res.send(JSON.stringify(this.geojson));
    }

    public OpenFile() {
        fs.readFile(this.file, 'utf8', (err, data) => {
            if (!err) {
                this.geojson = JSON.parse(data);
                this.geojson.features.forEach((f: csComp.Services.IFeature) => {
                    this.initFeature(f);
                });
            }
            else {
                console.log('error:' + this.file);
{'fraction_non_alphanumeric': 0.13170731707317074, 'fraction_numerical': 0.0004065040650406504, 'mean_word_length': 3.0974188176519566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4038827', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1325, 'n_words': 338}