<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hadouken.Http;
using Hadouken.BitTorrent;

namespace Hadouken.Impl.Http.Api
{
    [ApiAction("gettorrents")]
    public class GetTorrents : ApiAction
    {
        private IBitTorrentEngine _torrentEngine;

        public GetTorrents(IBitTorrentEngine torrentEngine)
        {
            _torrentEngine = torrentEngine;
        }

        public override ActionResult Execute(IHttpContext context)
        {
            return Json(new
            {
                labels = new object[] {
                },
                torrents= (from t in _torrentEngine.Managers.Values
                           select new object[]
                           {
                               t.InfoHash,
                               t.State,
                               t.Torrent.Name,
                               t.Torrent.Size,
                               (int)t.Progress * 10,
                               t.DownloadedBytes,
                               t.UploadedBytes,
                               (t.DownloadedBytes == 0 ? 0 : (int)((t.UploadedBytes / t.DownloadedBytes) * 10))
                           })
            });
        }
    }
}
<commit_msg>Completed `gettorrents` action to output in same format as the UI expects.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hadouken.Http;
using Hadouken.BitTorrent;

namespace Hadouken.Impl.Http.Api
{
    [ApiAction("gettorrents")]
    public class GetTorrents : ApiAction
    {
        private IBitTorrentEngine _torrentEngine;

        public GetTorrents(IBitTorrentEngine torrentEngine)
        {
            _torrentEngine = torrentEngine;
        }

        public override ActionResult Execute(IHttpContext context)
        {
            return Json(new
            {
                labels = new object[] {
                },
                torrents= (from t in _torrentEngine.Managers.Values
                           select new object[]
                           {
                               t.InfoHash,
                               t.State,
                               t.Torrent.Name,
                               t.Torrent.Size,
                               (int)t.Progress * 10,
                               t.DownloadedBytes,
                               t.UploadedBytes,
                               (t.DownloadedBytes == 0 ? 0 : (int)((t.UploadedBytes / t.DownloadedBytes) * 10)),
                               t.UploadSpeed,
                               t.DownloadSpeed,
                               t.ETA.TotalSeconds,
                               t.Label,
                               t.Peers.Where(p => !p.IsSeeder),
                               t.Trackers.Sum(tr => tr.Incomplete),
                               t.Peers.Where(p => p.IsSeeder),
                               t.Trackers.Sum(tr => tr.Complete),
                               -1, // availability
                               -1, // queue position
                               t.RemainingBytes,
                               "", // download url
                               "", // rss feed url
                               (t.State == TorrentState.Error ? "Error: --" : ""),
                               -1, // stream id
                               t.StartTime.ToUnixTime(),
                               (t.CompletedTime.HasValue ? t.CompletedTime.Value.ToUnixTime() : -1),
                               "", // app update url
                               t.SavePath,
                               t.Complete
                           })
            });
        }
    }
}

{'fraction_non_alphanumeric': 0.07952182952182953, 'fraction_numerical': 0.004158004158004158, 'mean_word_length': 0.8757309941520468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '666900', 'n_tokens_mistral': 941, 'n_tokens_neox': 908, 'n_words': 167}