Compare commits
	
		
			2 Commits
		
	
	
		
			d19bef33d2
			...
			8c7e67acc6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8c7e67acc6 | |||
| 0fdd51a3ec | 
@ -59,8 +59,39 @@ namespace EliteBGS.BGS {
 | 
			
		||||
                return builder.ToString();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach (SellCargo sell in sold) {
 | 
			
		||||
                builder.AppendFormat("{0}\n", sell.ToString());
 | 
			
		||||
 | 
			
		||||
            // This groups everything together by cargo sold, and then by market sold to.
 | 
			
		||||
            //  Dictionary<string Cargo, Dictionary<string Market, { Market, Amount, Profit }> >
 | 
			
		||||
            var entries = sold.GroupBy(x => x.Cargo,
 | 
			
		||||
                                       (key, cargos) => new {
 | 
			
		||||
                                           Cargo = key,
 | 
			
		||||
                                           Markets = cargos.GroupBy(y => y.Market,
 | 
			
		||||
                                                               (market, markets) => new {
 | 
			
		||||
                                                                   Market = market,
 | 
			
		||||
                                                                   Amount = markets.Sum(x => x.Amount),
 | 
			
		||||
                                                                   Profit = markets.Sum(x => x.Profit)
 | 
			
		||||
                                                               })
 | 
			
		||||
                                       }
 | 
			
		||||
                                       )
 | 
			
		||||
                              ;
 | 
			
		||||
 | 
			
		||||
            foreach (var cargo in entries) {
 | 
			
		||||
                foreach (var market in cargo.Markets) {
 | 
			
		||||
                    builder.AppendFormat("Sold {0} {1} to the {2}",
 | 
			
		||||
                            market.Amount,
 | 
			
		||||
                            cargo.Cargo,
 | 
			
		||||
                            market.Market
 | 
			
		||||
                        );
 | 
			
		||||
 | 
			
		||||
                    if (market.Profit != 0) {
 | 
			
		||||
                        builder.AppendFormat(" ({0} {1})",
 | 
			
		||||
                            Credits.FormatCredits(market.Profit),
 | 
			
		||||
                            market.Profit < 0 ? "loss" : "profit"
 | 
			
		||||
                            );
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    builder.Append("\n");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            builder.AppendFormat("\n");
 | 
			
		||||
 | 
			
		||||
@ -50,13 +50,16 @@ namespace EliteBGS.BGS {
 | 
			
		||||
                          where file.NormalisedTimestamp >= start && file.NormalisedTimestamp <= end
 | 
			
		||||
                          select file.Entries
 | 
			
		||||
                          ;
 | 
			
		||||
            var relevant = from log in entries.SelectMany(array => array)
 | 
			
		||||
                           where IsRelevant(log)
 | 
			
		||||
                           select log
 | 
			
		||||
                           ;
 | 
			
		||||
            Scan(entries.SelectMany(x => x).ToList());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Scan(List<Entry> entries) {
 | 
			
		||||
            if (entries.Count <= 0) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            List<Entry> relevant = entries.Where(x => IsRelevant(x)).ToList();
 | 
			
		||||
            Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
 | 
			
		||||
 | 
			
		||||
            Dictionary<string, int> buyCost = new Dictionary<string, int>();
 | 
			
		||||
 | 
			
		||||
            string current_system = null;
 | 
			
		||||
 | 
			
		||||
@ -12,16 +12,10 @@ namespace EliteBGS.BGS {
 | 
			
		||||
            Entries.Add(e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override string ToString() {
 | 
			
		||||
            StringBuilder builder = new StringBuilder();
 | 
			
		||||
            var sold = Entries.OfType<MarketSellEntry>().ToArray();
 | 
			
		||||
 | 
			
		||||
            if (sold == null || sold.Length == 0) {
 | 
			
		||||
                return builder.ToString();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach (MarketSellEntry sell in sold) {
 | 
			
		||||
        public string Cargo {
 | 
			
		||||
            get {
 | 
			
		||||
                string cargo;
 | 
			
		||||
                var sell = Entries.OfType<MarketSellEntry>().First();
 | 
			
		||||
 | 
			
		||||
                if (!string.IsNullOrEmpty(sell.TypeLocalised)) {
 | 
			
		||||
                    cargo = sell.TypeLocalised;
 | 
			
		||||
@ -32,10 +26,34 @@ namespace EliteBGS.BGS {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return cargo;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string Market {
 | 
			
		||||
            get {
 | 
			
		||||
                var sell = Entries.OfType<MarketSellEntry>().First();
 | 
			
		||||
                return sell.BlackMarket ? "Black Market" : "Commodity Market";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public long Amount {
 | 
			
		||||
            get { return Entries.OfType<MarketSellEntry>().Sum(x => x.Count); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override string ToString() {
 | 
			
		||||
            StringBuilder builder = new StringBuilder();
 | 
			
		||||
            var sold = Entries.OfType<MarketSellEntry>().ToArray();
 | 
			
		||||
 | 
			
		||||
            if (sold == null || sold.Length == 0) {
 | 
			
		||||
                return builder.ToString();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach (MarketSellEntry sell in sold) {
 | 
			
		||||
                builder.AppendFormat("Sold {0} {1} to the {2}",
 | 
			
		||||
                    sell.Count,
 | 
			
		||||
                    cargo,
 | 
			
		||||
                    sell.BlackMarket ? "Black Market" : "Commodity Market"
 | 
			
		||||
                    Cargo,
 | 
			
		||||
                    Market
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                if (Profit != 0) {
 | 
			
		||||
 | 
			
		||||
@ -59,6 +59,7 @@
 | 
			
		||||
    <Reference Include="System.Design" />
 | 
			
		||||
    <Reference Include="System.Drawing" />
 | 
			
		||||
    <Reference Include="System.Security" />
 | 
			
		||||
    <Reference Include="System.Windows.Forms" />
 | 
			
		||||
    <Reference Include="System.Xml" />
 | 
			
		||||
    <Reference Include="Microsoft.CSharp" />
 | 
			
		||||
    <Reference Include="System.Core" />
 | 
			
		||||
@ -90,6 +91,9 @@
 | 
			
		||||
    <Compile Include="BGS\FactionKillBonds.cs" />
 | 
			
		||||
    <Compile Include="EDDB\PopulatedSystems.cs" />
 | 
			
		||||
    <Compile Include="EDDB\Stations.cs" />
 | 
			
		||||
    <Compile Include="LoadEntriesWindow.xaml.cs">
 | 
			
		||||
      <DependentUpon>LoadEntriesWindow.xaml</DependentUpon>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Resources.Designer.cs">
 | 
			
		||||
      <AutoGen>True</AutoGen>
 | 
			
		||||
      <DesignTime>True</DesignTime>
 | 
			
		||||
@ -110,6 +114,10 @@
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
    </Page>
 | 
			
		||||
    <Page Include="LoadEntriesWindow.xaml">
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
    </Page>
 | 
			
		||||
    <Page Include="MainWindow.xaml">
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								LoadEntriesWindow.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								LoadEntriesWindow.xaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
<Window x:Class="EliteBGS.LoadEntriesWindow"
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:local="clr-namespace:EliteBGS"
 | 
			
		||||
        mc:Ignorable="d"
 | 
			
		||||
        Title="Load Entries" Height="450" Width="600">
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition Height="*" />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
        </Grid.RowDefinitions>
 | 
			
		||||
        <Grid.ColumnDefinitions>
 | 
			
		||||
            <ColumnDefinition Width="Auto" />
 | 
			
		||||
            <ColumnDefinition Width="*" />
 | 
			
		||||
            <ColumnDefinition Width="Auto" />
 | 
			
		||||
        </Grid.ColumnDefinitions>
 | 
			
		||||
        <TextBox x:Name="Lines" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap" Grid.Row="0" Height="Auto" Grid.Column="0" Grid.ColumnSpan="3" VerticalScrollBarVisibility="Visible" />
 | 
			
		||||
        <Button x:Name="Load" Content="Load Entries" Grid.Row="1" Margin="5,5,5,5" Height="Auto" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Load_Click" />
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
							
								
								
									
										52
									
								
								LoadEntriesWindow.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								LoadEntriesWindow.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using EDJournal;
 | 
			
		||||
using System.Windows.Controls;
 | 
			
		||||
using System.Windows.Data;
 | 
			
		||||
using System.Windows.Documents;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
 | 
			
		||||
namespace EliteBGS {
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for LoadEntriesWindow.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class LoadEntriesWindow : Window {
 | 
			
		||||
        public delegate void EntriesLoadedDelegate(List<Entry> entries);
 | 
			
		||||
 | 
			
		||||
        public event EntriesLoadedDelegate EntriesLoaded;
 | 
			
		||||
 | 
			
		||||
        public LoadEntriesWindow() {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Load_Click(object sender, RoutedEventArgs e) {
 | 
			
		||||
            string lines = Lines.Text.Trim();
 | 
			
		||||
            if (lines.Length <= 0) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                List<Entry> entries = new List<Entry>();
 | 
			
		||||
 | 
			
		||||
                foreach (string line in lines.Split('\n')) {
 | 
			
		||||
                    Entry entry = Entry.Parse(line);
 | 
			
		||||
                    entries.Add(entry);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (entries.Count > 0) {
 | 
			
		||||
                    EntriesLoaded?.Invoke(entries);
 | 
			
		||||
                }
 | 
			
		||||
            } catch (Exception exception) {
 | 
			
		||||
                MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}",
 | 
			
		||||
                    exception.ToString()));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -7,7 +7,7 @@
 | 
			
		||||
        xmlns:local="clr-namespace:EliteBGS"
 | 
			
		||||
        xmlns:BGS="clr-namespace:EliteBGS.BGS" xmlns:Util="clr-namespace:EliteBGS.Util" d:DataContext="{d:DesignInstance Type=Util:AppConfig}" x:Name="window" x:Class="EliteBGS.MainWindow"
 | 
			
		||||
        mc:Ignorable="d"
 | 
			
		||||
        Title="Elite: Dangerous BGS Helper" Height="520" Width="890" Icon="EliteBGS.ico">
 | 
			
		||||
        Title="Elite: Dangerous BGS Helper" Height="520" Width="890" Icon="EliteBGS.ico" Closing="window_Closing">
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.ColumnDefinitions>
 | 
			
		||||
            <ColumnDefinition Width="*"/>
 | 
			
		||||
@ -49,6 +49,8 @@
 | 
			
		||||
                        <DatePicker x:Name="startdate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
 | 
			
		||||
                        <Label Content="To:" Height="26.2857142857143" VerticalAlignment="Top"/>
 | 
			
		||||
                        <DatePicker x:Name="enddate" Height="26.2857142857143" VerticalAlignment="Center" HorizontalAlignment="Center"/>
 | 
			
		||||
                        <Separator Margin="1" VerticalAlignment="Center" MinWidth="1" HorizontalAlignment="Center" MinHeight="22"/>
 | 
			
		||||
                        <Button x:Name="ManuallyParse" Content="Manually Parse JSON" Click="ManuallyParse_Click" />
 | 
			
		||||
                    </ToolBar>
 | 
			
		||||
                    <TreeView x:Name="entries" Margin="0,0,0,0" Grid.ColumnSpan="3" Grid.Row="2" KeyUp="entries_KeyUp">
 | 
			
		||||
                        <TreeView.ItemTemplate>
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,8 @@ namespace EliteBGS {
 | 
			
		||||
 | 
			
		||||
        public Report Report => report;
 | 
			
		||||
 | 
			
		||||
        private LoadEntriesWindow loadentries = new LoadEntriesWindow();
 | 
			
		||||
 | 
			
		||||
        private static readonly List<IDiscordLogGenerator> logtypes = new List<IDiscordLogGenerator>() {
 | 
			
		||||
            new NonaDiscordLog(),
 | 
			
		||||
            new GenericDiscordLog(),
 | 
			
		||||
@ -43,6 +45,8 @@ namespace EliteBGS {
 | 
			
		||||
                /* ignored */
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            loadentries.EntriesLoaded += Loadentries_EntriesLoaded;
 | 
			
		||||
 | 
			
		||||
            report.OnLog += Report_OnLog;
 | 
			
		||||
 | 
			
		||||
            foreach (IDiscordLogGenerator type in logtypes) {
 | 
			
		||||
@ -83,6 +87,17 @@ namespace EliteBGS {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Loadentries_EntriesLoaded(List<Entry> lines) {
 | 
			
		||||
            try {
 | 
			
		||||
                report.Scan(lines);
 | 
			
		||||
                RefreshObjectives();
 | 
			
		||||
            } catch (Exception exception) {
 | 
			
		||||
                Log("Something went terribly wrong while parsing the E:D player journal.");
 | 
			
		||||
                Log("Please send this to CMDR Hekateh:");
 | 
			
		||||
                Log(exception.ToString());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Api_StationsAvailable() {
 | 
			
		||||
            try {
 | 
			
		||||
                stations_db = api.MakeStations();
 | 
			
		||||
@ -321,5 +336,13 @@ namespace EliteBGS {
 | 
			
		||||
            string template = LogType.SelectedItem.ToString();
 | 
			
		||||
            config.Global.LastUsedDiscordTemplate = template;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ManuallyParse_Click(object sender, RoutedEventArgs e) {
 | 
			
		||||
            loadentries.Show();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
 | 
			
		||||
            loadentries.Close();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user