<commit_before>﻿using System;
using System.Collections.Generic;
using UnityEngine;


namespace KERBALISM
{


	public static class FileManager
	{

		/// <summary>
		/// If short_strings parameter is true then the strings used for display of the data will be shorter when inflight.
		/// </summary>
		public static void Fileman(this Panel p, Vessel v, bool short_strings = false)
		{
			// avoid corner-case when this is called in a lambda after scene changes
			v = FlightGlobals.FindVessel(v.id);

			// if vessel doesn't exist anymore, leave the panel empty
			if (v == null) return;

			// get info from the cache
			Vessel_info vi = Cache.VesselInfo(v);

			// if not a valid vessel, leave the panel empty
			if (!vi.is_valid) return;

			// set metadata
			p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(40)), " <color=#cccccc>FILE MANAGER</color>"));
			p.Width(Styles.ScaleWidthFloat(465.0f));
			p.paneltype = Panel.PanelType.data;

 			// time-out simulation
			if (p.Timeout(vi)) return;

			var drives = DB.Vessel(v).drives;

			int filesCount = 0;
			double usedDataCapacity = 0;
			double totalDataCapacity = 0;

			int samplesCount = 0;
			int usedSlots = 0;
			int totalSlots = 0;
			double totalMass = 0;

			foreach (var idDrivePair in drives)
			{
				var drive = idDrivePair.Value;

				usedDataCapacity += drive.FilesSize();
				totalDataCapacity += drive.dataCapacity;
				filesCount += drive.files.Count;

				usedSlots += drive.SamplesSize();
				totalSlots += drive.sampleCapacity;
				samplesCount += drive.samples.Count;
				foreach (var sample in drive.samples.Values) totalMass += sample.mass;
			}

			if(filesCount > 0 || totalDataCapacity > 0)
			{
				var title = "DATA " + Lib.HumanReadableDataSize(usedDataCapacity) + Lib.BuildString(" (", Lib.HumanReadablePerc((totalDataCapacity - usedDataCapacity) / totalDataCapacity), " available)");
				p.AddSection(title);

				foreach (var idDrivePair in drives)
				{
					uint partId = idDrivePair.Key;
					var drive = idDrivePair.Value;
					foreach (var pair in drive.files)
					{
						string filename = pair.Key;
						File file = pair.Value;
						Render_file(p, partId, filename, file, drive, short_strings && Lib.IsFlight(), Cache.VesselInfo(v).connection.rate);
					}
				}

				if(filesCount == 0) p.AddContent("<i>no files</i>", string.Empty);
			}

			if(samplesCount > 0 || totalSlots > 0)
			{
				var title = "SAMPLES " + Lib.HumanReadableMass(totalMass) + " (" + usedSlots + "/" + Lib.HumanReadableSampleSize(totalSlots) + " available)";
				p.AddSection(title);
<commit_msg>don't sum up the capacities of private drives in the UI<commit_after>﻿using System;
using System.Collections.Generic;
using UnityEngine;


namespace KERBALISM
{


	public static class FileManager
	{

		/// <summary>
		/// If short_strings parameter is true then the strings used for display of the data will be shorter when inflight.
		/// </summary>
		public static void Fileman(this Panel p, Vessel v, bool short_strings = false)
		{
			// avoid corner-case when this is called in a lambda after scene changes
			v = FlightGlobals.FindVessel(v.id);

			// if vessel doesn't exist anymore, leave the panel empty
			if (v == null) return;

			// get info from the cache
			Vessel_info vi = Cache.VesselInfo(v);

			// if not a valid vessel, leave the panel empty
			if (!vi.is_valid) return;

			// set metadata
			p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(40)), " <color=#cccccc>FILE MANAGER</color>"));
			p.Width(Styles.ScaleWidthFloat(465.0f));
			p.paneltype = Panel.PanelType.data;

 			// time-out simulation
			if (p.Timeout(vi)) return;

			var drives = DB.Vessel(v).drives;

			int filesCount = 0;
			double usedDataCapacity = 0;
			double totalDataCapacity = 0;

			int samplesCount = 0;
			int usedSlots = 0;
			int totalSlots = 0;
			double totalMass = 0;

			foreach (var idDrivePair in drives)
			{
				var drive = idDrivePair.Value;

				if(!drive.is_private)
				{
					usedDataCapacity += drive.FilesSize();
					totalDataCapacity += drive.dataCapacity;

					usedSlots += drive.SamplesSize();
					totalSlots += drive.sampleCapacity;
				}

				filesCount += drive.files.Count;
				samplesCount += drive.samples.Count;
				foreach (var sample in drive.samples.Values) totalMass += sample.mass;
			}

			if(filesCount > 0 || totalDataCapacity > 0)
			{
				var title = "DATA " + Lib.HumanReadableDataSize(usedDataCapacity) + Lib.BuildString(" (", Lib.HumanReadablePerc((totalDataCapacity - usedDataCapacity) / totalDataCapacity), " available)");
				p.AddSection(title);

				foreach (var idDrivePair in drives)
				{
					uint partId = idDrivePair.Key;
					var drive = idDrivePair.Value;
					foreach (var pair in drive.files)
					{
						string filename = pair.Key;
						File file = pair.Value;
						Render_file(p, partId, filename, file, drive, short_strings && Lib.IsFlight(), Cache.VesselInfo(v).connection.rate);
					}
				}

				if(filesCount == 0) p.AddContent("<i>no files</i>", string.Empty);
			}

			if(samplesCount > 0 || totalSlots > 0)
			{
				var title = "SAMPLES " + Lib.HumanReadableMass(totalMass) + " (" + usedSlots + "/" + Lib.HumanReadableSampleSize(totalSlots) + " available)";
				p.AddSection(title);

{'fraction_non_alphanumeric': 0.11906113950406966, 'fraction_numerical': 0.0068143100511073255, 'mean_word_length': 3.2750809061488675, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '222633', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1643, 'n_words': 445}