<commit_before>﻿/*
 * Copyright © 2016 - 2020 EDDiscovery development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 * 
 * EDDiscovery is not affiliated with Frontier Developments plc.
 */
using EDDiscovery.Controls;
using EliteDangerousCore;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace EDDiscovery.UserControls
{
    public partial class UserControlEngineering : UserControlCommonBase
    {
        RecipeFilterSelector efs;
        RecipeFilterSelector mfs;
        RecipeFilterSelector ufs;
        RecipeFilterSelector lfs;
        RecipeFilterSelector matfs;

        private List<string> levels = new List<string> { "1", "2", "3", "4", "5", "NA"};

        private string dbWSave = "Wanted";
        private string dbOSave = "Order";
        private string dbEngFilterSave = "GridControlEngineerFilter";
        private string dbModFilterSave = "GridControlModuleFilter";
        private string dbLevelFilterSave = "GridControlLevelFilter";
        private string dbUpgradeFilterSave = "GridControlUpgradeFilter";
        private string dbMaterialFilterSave = "GridControlMaterialFilter";
        private string dbHistoricMatsSave = "GridHistoricMaterials";
        private string dbWordWrap = "WordWrap";

        int[] RowToRecipe;        // order
        int[] WantedPerRecipe;       // wanted, in order terms

        internal bool isEmbedded = false;
        internal bool isHistoric = false;
        public Action<List<Tuple<Recipes.Recipe, int>>> OnDisplayComplete;  // called when display complete, for use by other UCs using this

        HistoryEntry last_he = null;

        #region Init

        public UserControlEngineering()
        {
            DBBaseName = "Engineering";
            InitializeComponent();
        }

        public override void Init()
        {
            dataGridViewEngineering.MakeDoubleBuffered();
            extCheckBoxWordWrap.Checked = GetSetting(dbWordWrap, false);
            UpdateWordWrap();
            extCheckBoxWordWrap.Click += extCheckBoxWordWrap_Click;

            RowToRecipe = GetSetting(dbOSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);
            if (RowToRecipe.Max() >= Recipes.EngineeringRecipes.Count || RowToRecipe.Min() < 0 || RowToRecipe.Distinct().Count() != Recipes.EngineeringRecipes.Count)       // if not distinct..
            {
                for (int i = 0; i < RowToRecipe.Length; i++)          // reset
                    RowToRecipe[i] = i;
            }

            WantedPerRecipe = GetSetting(dbWSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);

            List<string> engineers = Recipes.EngineeringRecipes.SelectMany(r => r.engineers).Distinct().ToList();
            engineers.Sort();
            efs = new RecipeFilterSelector(engineers);
            efs.SaveSettings += (newvalue, e) => { PutSetting(dbEngFilterSave, newvalue); Display(); };

            lfs = new RecipeFilterSelector(levels);
            lfs.SaveSettings += (newvalue, e) => { PutSetting(dbLevelFilterSave, newvalue); Display(); };

            List<string> modules = Recipes.EngineeringRecipes.SelectMany(r => r.modules).Distinct().ToList();
            modules.Sort();
            mfs = new RecipeFilterSelector(modules);
            mfs.SaveSettings += (newvalue, e) => { PutSetting(dbModFilterSave, newvalue); Display(); };

            var upgrades = Recipes.EngineeringRecipes.Select(r => r.Name).Distinct().ToList();
            upgrades.Sort();
            ufs = new RecipeFilterSelector(upgrades);
            ufs.SaveSettings += (newvalue, e) => { PutSetting(dbUpgradeFilterSave, newvalue); Display(); };

            List<string> matLongNames = Recipes.EngineeringRecipes.SelectMany(r => r.Ingredients).Select(x=>x.Name).Distinct().ToList();<commit_msg>Engineering - sort the list of materials alphabetically<commit_after>﻿/*
 * Copyright © 2016 - 2020 EDDiscovery development team
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 * 
 * EDDiscovery is not affiliated with Frontier Developments plc.
 */
using EDDiscovery.Controls;
using EliteDangerousCore;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace EDDiscovery.UserControls
{
    public partial class UserControlEngineering : UserControlCommonBase
    {
        RecipeFilterSelector efs;
        RecipeFilterSelector mfs;
        RecipeFilterSelector ufs;
        RecipeFilterSelector lfs;
        RecipeFilterSelector matfs;

        private List<string> levels = new List<string> { "1", "2", "3", "4", "5", "NA"};

        private string dbWSave = "Wanted";
        private string dbOSave = "Order";
        private string dbEngFilterSave = "GridControlEngineerFilter";
        private string dbModFilterSave = "GridControlModuleFilter";
        private string dbLevelFilterSave = "GridControlLevelFilter";
        private string dbUpgradeFilterSave = "GridControlUpgradeFilter";
        private string dbMaterialFilterSave = "GridControlMaterialFilter";
        private string dbHistoricMatsSave = "GridHistoricMaterials";
        private string dbWordWrap = "WordWrap";

        int[] RowToRecipe;        // order
        int[] WantedPerRecipe;       // wanted, in order terms

        internal bool isEmbedded = false;
        internal bool isHistoric = false;
        public Action<List<Tuple<Recipes.Recipe, int>>> OnDisplayComplete;  // called when display complete, for use by other UCs using this

        HistoryEntry last_he = null;

        #region Init

        public UserControlEngineering()
        {
            DBBaseName = "Engineering";
            InitializeComponent();
        }

        public override void Init()
        {
            dataGridViewEngineering.MakeDoubleBuffered();
            extCheckBoxWordWrap.Checked = GetSetting(dbWordWrap, false);
            UpdateWordWrap();
            extCheckBoxWordWrap.Click += extCheckBoxWordWrap_Click;

            RowToRecipe = GetSetting(dbOSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);
            if (RowToRecipe.Max() >= Recipes.EngineeringRecipes.Count || RowToRecipe.Min() < 0 || RowToRecipe.Distinct().Count() != Recipes.EngineeringRecipes.Count)       // if not distinct..
            {
                for (int i = 0; i < RowToRecipe.Length; i++)          // reset
                    RowToRecipe[i] = i;
            }

            WantedPerRecipe = GetSetting(dbWSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);

            List<string> engineers = Recipes.EngineeringRecipes.SelectMany(r => r.engineers).Distinct().ToList();
            engineers.Sort();
            efs = new RecipeFilterSelector(engineers);
            efs.SaveSettings += (newvalue, e) => { PutSetting(dbEngFilterSave, newvalue); Display(); };

            lfs = new RecipeFilterSelector(levels);
            lfs.SaveSettings += (newvalue, e) => { PutSetting(dbLevelFilterSave, newvalue); Display(); };

            List<string> modules = Recipes.EngineeringRecipes.SelectMany(r => r.modules).Distinct().ToList();
            modules.Sort();
            mfs = new RecipeFilterSelector(modules);
            mfs.SaveSettings += (newvalue, e) => { PutSetting(dbModFilterSave, newvalue); Display(); };

            var upgrades = Recipes.EngineeringRecipes.Select(r => r.Name).Distinct().ToList();
            upgrades.Sort();
            ufs = new RecipeFilterSelector(upgrades);
            ufs.SaveSettings += (newvalue, e) => { PutSetting(dbUpgradeFilterSave, newvalue); Display(); };

            List<string> matLongNames = Recipes.EngineeringRecipes.SelectMany(r => r.Ingredients).Select(x=>x.Name).Distinct().ToList();
            matLongNames.Sort();
{'fraction_non_alphanumeric': 0.10012473069509015, 'fraction_numerical': 0.004762444721623767, 'mean_word_length': 2.942780509611086, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894047', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2298, 'n_words': 622}