<commit_before># -*- coding: utf-8 -*-
import json
import sys, getopt
import matplotlib.pyplot as plot
import matplotlib.patches as patches
import numpy as np
from matplotlib import rc

# Скрипт для построение графиков с помощью matplotlib. Данные для графика
# и параметры отрисовки передаются через json

def main(args):

    if len(args) == 0:
        print("No input json with task description passed")
        input("Press Enter to continue...")
        return

    print(args[0])
    # input("Press Enter to continue...")
    # какой-то трюк, чтобы можно было делать подписи кириллицей
    rc('font', **{'sans-serif': 'Arial',
                  'family': 'sans-serif'})

    f = open(args[0], 'r')
    jsonRaw = f.read()
    task = json.loads(jsonRaw)

    fig = plot.figure()
	
    subplots = {}
    subplotIndex = 1
    for i in range(0, task["rows"]):
        for j in range(0, task["columns"]):
            axes = fig.add_subplot(task["rows"], task["columns"], subplotIndex)
            subplots[subplotIndex] = axes
            setGrid(axes)
            subplotIndex += 1

    for sbplt in task["subplots"]:
        for item in sbplt["items"]:
            axes = subplots[sbplt["index"]]
            plot.sca(axes)
            setTitles(task, sbplt)

            if item["type"] == "Line2D":
                plotLine2D(item)
            elif item["type"] == "Histogram":
                plotHistogram(item)

    plot.tight_layout()
    plot.show()

    if "filename" in task and task["filename"] is not None:
        plot.savefig(task["filename"], dpi=300)

# Отрисовка 2D линии
def plotLine2D(line):
    c = 'r' if "color" not in line else line["color"]
    m = '' if "marker" not in line else line["marker"]
    lw = 1 if "lineWidth" not in line else line["lineWidth"]
    ms = 1 if "markerSize" not in line else line["markerSize"]
    ls = '-' if "lineStyle" not in line else line["lineStyle"]
    plot.plot(line["x"], line["y"], color=c, marker=m, lw=lw, ms=ms, ls=ls)
    plot.hold(True)

# Отрисовка гистограммы
def plotHistogram(line):
    plot.hist(line["y"],50)
    plot.hold(True)

# Настройка сетки
def setGrid(axes):
    axes.grid(which='both')
    axes.grid(which='minor', alpha=0.2)
    axes.grid(which='major', alpha=0.5)
    axes.grid('on')

# Настройка подписей к осям и графику
def setTitles(task, axes):
    plot.title(u"{0}".format(axes["title"]))
    plot.ylabel(axes["xtitle"])
    plot.xlabel(axes["ytitle"])

<commit_msg>Commenting dasPlot.py<commit_after># -*- coding: utf-8 -*-
import json
import sys, getopt
import matplotlib.pyplot as plot
import matplotlib.patches as patches
import numpy as np
from matplotlib import rc

# Script builds a matplotlib figure based on information, passed to it through json file.
# Path to the JSON must be passed in first command line argument.

# a trick to enable text labels in cyrillic
rc('font', **{'sans-serif': 'Arial','family': 'sans-serif'})


def main(args):

    if len(args) == 0:
        print("No input path to json passed")
        input("Press Enter to continue...")
        return

    print(args[0])

    f = open(args[0], 'r')
    json_raw = f.read()
    task = json.loads(json_raw)

    fig = plot.figure()

    # precreate, make basic settings and save subplots
    subplots = {}
    subplot_index = 1
    for i in range(0, task["rows"]):
        for j in range(0, task["columns"]):
            axes = fig.add_subplot(task["rows"], task["columns"], subplot_index)
            subplots[subplot_index] = axes
            setGrid(axes)
            subplot_index += 1

    # draw items on each subplot
    for axes in task["subplots"]:
        for item in axes["items"]:
            axes = subplots[axes["index"]]
            plot.sca(axes)
            setTitles(task, axes)

            if item["type"] == "Line2D":
                plotLine2D(item)
            elif item["type"] == "Histogram":
                plotHistogram(item)

    plot.tight_layout()
    plot.show()

    # if file name is provided in json, then save figure to file
    if "filename" in task and task["filename"] is not None:
        plot.savefig(task["filename"], dpi=300)

# Plot simple 2D line
def plotLine2D(line):
    c = 'r' if "color" not in line else line["color"]
    m = '' if "marker" not in line else line["marker"]
    lw = 1 if "lineWidth" not in line else line["lineWidth"]
    ms = 1 if "markerSize" not in line else line["markerSize"]
    ls = '-' if "lineStyle" not in line else line["lineStyle"]
    plot.plot(line["x"], line["y"], color=c, marker=m, lw=lw, ms=ms, ls=ls)
    plot.hold(True)

# Plot histogram
def plotHistogram(line):
    plot.hist(line["y"],50)
    plot.hold(True)

# Setup the grid
def setGrid(axes):
    axes.grid(which='both')
    axes.grid(which='minor', alpha=0.2)
    axes.grid(which='major', alpha=0.5)
    axes.grid('on')

# Setup titeles
def setTitles(task, axes):
    plot.title(u"{0}".format(axes["title"]))
    plot.ylabel(axes["xtitle"])
    plot.xlabel(axes["ytitle"])

# entry point
{'fraction_non_alphanumeric': 0.14148489093456074, 'fraction_numerical': 0.009605763458074845, 'mean_word_length': 2.829885057471264, 'pattern_counts': {'":': 4, '<': 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': '5370478', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1685, 'n_words': 477}