Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Алешев Руслан #176

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

artBETEP
Copy link

@artBETEP artBETEP commented Feb 6, 2024

@grantsev
Задание TagsCloudResult

commandLine = new();
commandLine.Filename = Path.GetTempFileName();
commandLine.Output = Path.GetTempFileName();
//commandLine.FontFamily = "Arial";

This comment was marked as resolved.

// Act
var sut = provider.Points().Skip(maxPointsCount-2).First();

// Assert

This comment was marked as resolved.

return new List<Color>() { Color.White };
}

var c = colors.Split(',').Select(x => Color.FromName(x)).ToList();

This comment was marked as resolved.

wordFrequency = new Dictionary<string, int>();
}

public void Analyze(string text, string exclude = "")

This comment was marked as resolved.

{
if (!File.Exists(excludedWordsPath))
{
return;

This comment was marked as resolved.

var rect = PutNextRectangle(size);
if (!rect.IsSuccess)
{
yield return Result.Fail<TextImage>("Can't place more rectangles. Try to increase canvas size");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А есть тут какой-то сакральный смысл в ленивости вычислений? На чем экономим?

Copy link
Author

@artBETEP artBETEP Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Смысл в ленивости: Точки - суть кандидаты для размещения слов. Врят ли имеет смысл вычислять все точки, если нам надо будет разместить лишь пару слов.

public static Result<Image> Draw(Size size, IEnumerable<Result<TextImage>> textImages, Color? bgColor = null)
{
var image = new Bitmap(size.Width, size.Height);
var gr = Graphics.FromImage(image);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDisposable жеж

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Класс переименован в Painter, интерфейс реализован.

using TagsCloudVisualization;
using TagsCloudContainer.TagCloudBuilder;

namespace ResutlTests

This comment was marked as resolved.


layouter.Initialize(appSettings.DrawingSettings, analyzer.GetAnalyzedText());

Visualizer.Draw(appSettings.DrawingSettings.Size,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ето не функциональное программирование, построй логику на Result и Then

что-то типа, должен получиться лаконичный пайплайн обработки:

 var res = fileReaderFactory
            .Create(settings.InputPath)
            .Then(fileReader=> fileReader.GetLines(settings.InputPath))
            .Then(lemmatizer.GetLemmas)
            .Then(filter.FilterWords)
            .Then(weigher.GetWeightedWords)
            .Then(painter.CreateImage)
            .Then(bitmap => saver.Save(bitmap, settings.OutputPath, settings.OutputFormat));

        if (!res.IsSuccess)
            Console.Write(res.Error);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Логику переделал

{
if (IsSuccess) return Value;

ErrorParser.Critical(Error);

This comment was marked as resolved.

var rawText = TextFileReader.ReadText(appSettings.TextFile);
if (rawText.IsSuccess)
{
var res = FrequencyAnalyzer.Analyze(rawText.GetValueOrDefault(), appSettings.FilterFile)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RawText можно тож через Then передавать же, не?
Тебе просто нужен Then

public static Result<TOutput> Then<TInput, TOutput>(this Result<TInput> input, Func<TInput, Result<TOutput>> continuation)
    {
        return input.IsSuccess && input.Value != null
            ? continuation(input.Value)
            : Fail<TOutput>(input.Error);
    }

Суть - не кидаешь эксепшоны, складываешь в монаду ошибки, так тебе не понадобится GetValueOrDefault() и тд

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants