<commit_before>// Import Agenda
import Agenda = require("agenda");
// Import injectable and reflect metadata for dependency injection
import { inject, injectable } from "inversify";
import "reflect-metadata";
// Import interfaces for class implementation and dependency injection
import { IPeriodicJob } from "../interfaces/IPeriodicJob";
import { IPIWebAPIService } from "../interfaces/IPIWebAPIService";
// import specific external modules from node_modules
import * as fs from "mz/fs";
const csv = require("csv.js");

@injectable()
export class HelloSinusoid implements IPeriodicJob {

    // Job config
    public config = {
        // Every 15 seconds cron notation
        interval: "*/15 * * * * *",
    };

    // Get instance of PIWebAPIService with dependency injection
    @inject("IPIWebAPIService")
    private service: IPIWebAPIService;

    // Job run function
    public async run(job: Agenda.Job, done: any) {
        try {
            // Await actual Sinusoid value from PIWebAPI service with basic auth defined in configs/piwebapi_config.ts
            const result = await this.service.getPIPointDataByPath("\\\\PI\\SINUSOID");
            // Define constants for csv writing
            const newLine = "\r\n";
            const dateString: string = `${new Date().getDate()}_${new Date().getMonth()}_${new Date().getFullYear()}`;
            const file = `output/helloSinusoid_${dateString}.csv`;
            // Append to existing file or create new file
            if (await fs.exists(file)) {
                const encoded = csv.encode(result, ",", false) + newLine;
                await fs.appendFile(file, encoded);
            } else {
                const encoded = csv.encode(result, ",", true) + newLine;
                await fs.writeFile(file, encoded);
            }
            done();
        } catch (error) {
            console.error(error);
            done();
        }
    }
}
<commit_msg>update comment<commit_after>// Import Agenda
import Agenda = require("agenda");
// Import injectable and reflect metadata for dependency injection
import { inject, injectable } from "inversify";
import "reflect-metadata";
// Import interfaces for class implementation and dependency injection
import { IPeriodicJob } from "../interfaces/IPeriodicJob";
import { IPIWebAPIService } from "../interfaces/IPIWebAPIService";
// import specific external modules from node_modules
import * as fs from "mz/fs";
const csv = require("csv.js");

@injectable()
export class HelloSinusoid implements IPeriodicJob {

    // Job config
    public config = {
        // Every 15 seconds cron notation
        interval: "*/15 * * * * *",
    };

    // Get instance of PIWebAPIService with dependency injection
    @inject("IPIWebAPIService")
    private service: IPIWebAPIService;

    // Job run function
    public async run(job: Agenda.Job, done: any) {
        try {
            // Await actual Sinusoid value from PIWebAPI service with basic auth defined in configs/piwebapi_config.ts
            const result = await this.service.getPIPointDataByPath("\\\\PI\\SINUSOID");
            // Define constants for csv writing
            const newLine = "\r\n";
            const dateString: string = `${new Date().getDate()}_${new Date().getMonth()}_${new Date().getFullYear()}`;
            const file = `output/helloSinusoid_${dateString}.csv`;
            // Append to existing file or create new file with headers
            if (await fs.exists(file)) {
                const encoded = csv.encode(result, ",", false) + newLine;
                await fs.appendFile(file, encoded);
            } else {
                const encoded = csv.encode(result, ",", true) + newLine;
                await fs.writeFile(file, encoded);
            }
            done();
        } catch (error) {
            console.error(error);
            done();
        }
    }
}

{'fraction_non_alphanumeric': 0.11500773594636411, 'fraction_numerical': 0.0020629190304280558, 'mean_word_length': 2.426678445229682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7370966', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1039, 'n_words': 317}