• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / SatisfactoryTree / 17901154145

22 Sep 2025 12:34AM UTC coverage: 66.023% (-1.8%) from 67.811%
17901154145

Pull #310

github

web-flow
Merge 46638118b into 0525e91df
Pull Request #310: Added new imported item type

426 of 752 branches covered (56.65%)

Branch coverage included in aggregate %.

94 of 187 new or added lines in 10 files covered. (50.27%)

62 existing lines in 3 files now uncovered.

1148 of 1632 relevant lines covered (70.34%)

1134.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.54
/src/SatisfactoryTree.Logic/Models/Plan.cs
1
using System.Security.Cryptography.X509Certificates;
2

3
namespace SatisfactoryTree.Logic.Models
4
{
5
    public class Plan
6
    {
7
        public List<Part> Parts { get; set; } = new();
2✔
8
        public List<Recipe> Recipes { get; set; } = new();
2✔
9
        public List<Building> Buildings { get; set; } = new();
2✔
10
        public List<Factory> Factories { get; set; } = new();
22✔
11

12
        public void UpdatePlanCalculations(FactoryCatalog factoryCatalog)
13
        {
2✔
14
            Calculator calculator = new();
2✔
15

16
            // Complete initial calculations
17
            foreach (Factory factory in Factories)
14✔
18
            {
4✔
19
                factory.ComponentParts = calculator.CalculateFactoryProduction(factoryCatalog, factory);
4✔
20
            }
4✔
21

22
            // Balance imports and exports across factories
23
            BalanceImportsAndExports();
2✔
24
        }
2✔
25

26
        private void BalanceImportsAndExports()
27
        {
2✔
28
            // Initialize exported quantities based on each factory's target production
29
            foreach (Factory factory in Factories)
14✔
30
            {
4✔
31
                foreach (ExportedItem exportedItem in factory.ExportedParts)
20✔
32
                {
4✔
33
                    // Initialize the exported quantity to the target production amount
34
                    exportedItem.PartQuantityExported = exportedItem.Item.Quantity;
4✔
35
                }
4✔
36
            }
4✔
37

38
            // Process each factory's import requests
39
            foreach (Factory factory in Factories)
14✔
40
            {
4✔
41
                foreach (KeyValuePair<int, ImportedItem> import in factory.ImportedParts)
16✔
42
                {
2✔
43
                    int sourceFactoryId = import.Key;
2✔
44
                    ImportedItem importedItem = import.Value;
2✔
45
                    
46
                    // Find the source factory
47
                    Factory? sourceFactory = Factories.FirstOrDefault(f => f.Id == sourceFactoryId);
4✔
48
                    if (sourceFactory == null)
2!
NEW
49
                    {
×
50
                        // Source factory not found
UNCOV
51
                        importedItem.PartQuantityImported = 0;
×
UNCOV
52
                        continue;
×
53
                    }
54

55
                    // Find the matching exported item
56
                    ExportedItem? exportedItem = sourceFactory.ExportedParts
2✔
57
                        .FirstOrDefault(e => e.Item.Name == importedItem.Item.Name);
4✔
58
                    
59
                    if (exportedItem == null)
2!
NEW
60
                    {
×
61
                        // Source factory doesn't export this item
NEW
62
                        importedItem.PartQuantityImported = 0;
×
UNCOV
63
                        continue;
×
64
                    }
65

66
                    double requestedQuantity = importedItem.Item.Quantity;
2✔
67
                    double availableQuantity = exportedItem.PartQuantityExported;
2✔
68

69
                    if (availableQuantity >= requestedQuantity)
2✔
70
                    {
1✔
71
                        // Full allocation possible
72
                        exportedItem.PartQuantityExported -= requestedQuantity;
1✔
73
                        importedItem.PartQuantityImported = requestedQuantity;
1✔
74
                    }
1✔
75
                    else if (availableQuantity > 0)
1!
76
                    {
1✔
77
                        // Partial allocation possible
78
                        importedItem.PartQuantityImported = availableQuantity;
1✔
79
                        exportedItem.PartQuantityExported = 0;
1✔
80
                    }
1✔
81
                    else
NEW
82
                    {
×
83
                        // No quantity available
UNCOV
84
                        importedItem.PartQuantityImported = 0;
×
UNCOV
85
                    }
×
86
                }
2✔
87
            }
4✔
88

89
            // Update the final PartQuantityExported to reflect what was actually used
90
            foreach (Factory factory in Factories)
14✔
91
            {
4✔
92
                foreach (ExportedItem exportedItem in factory.ExportedParts)
20✔
93
                {
4✔
94
                    // PartQuantityExported now represents what was actually exported (allocated)
95
                    double originalProduction = exportedItem.Item.Quantity;
4✔
96
                    double remainingQuantity = exportedItem.PartQuantityExported;
4✔
97
                    exportedItem.PartQuantityExported = originalProduction - remainingQuantity;
4✔
98
                }
4✔
99
            }
4✔
100
        }
2✔
101

102
        private void MarkAsExported(Factory sourceFactory, string itemName, double quantity, string destinationFactory)
UNCOV
103
        {
×
104
            // Initialize exports list if it doesn't exist
UNCOV
105
            if (sourceFactory.Surplus == null)
×
UNCOV
106
            {
×
UNCOV
107
                sourceFactory.Surplus = new();
×
UNCOV
108
            }
×
109

110
            // Find existing export entry or create new one
UNCOV
111
            var exportItem = sourceFactory.Surplus.FirstOrDefault(s => s.Name == $"Export to {destinationFactory}: {itemName}");
×
112

UNCOV
113
            if (exportItem != null)
×
UNCOV
114
            {
×
UNCOV
115
                exportItem.Quantity += quantity;
×
UNCOV
116
            }
×
117
            else
UNCOV
118
            {
×
UNCOV
119
                sourceFactory.Surplus.Add(new Item
×
UNCOV
120
                {
×
UNCOV
121
                    Name = $"Export to {destinationFactory}: {itemName}",
×
UNCOV
122
                    Quantity = quantity
×
UNCOV
123
                });
×
UNCOV
124
            }
×
UNCOV
125
        }
×
126

127
        private void AddPlanningNote(Factory factory, string note)
UNCOV
128
        {
×
129
            // For now, we'll use the surplus list to store planning notes
130
            // In a more complete implementation, you might want a dedicated Notes property
UNCOV
131
            factory.Surplus ??= new();
×
132

UNCOV
133
            factory.Surplus.Add(new Item
×
UNCOV
134
            {
×
UNCOV
135
                Name = $"Planning Note",
×
UNCOV
136
                Quantity = 0,
×
UNCOV
137
                // You might want to add a Notes property to Item class for this
×
UNCOV
138
                Building = note
×
UNCOV
139
            });
×
UNCOV
140
        }
×
141

142
        public Dictionary<string, List<string>> GetPlanValidationReport()
UNCOV
143
        {
×
UNCOV
144
            Dictionary<string, List<string>> report = new();
×
145

UNCOV
146
            foreach (Factory factory in Factories)
×
UNCOV
147
            {
×
UNCOV
148
                List<string> factoryIssues = new();
×
149

UNCOV
150
                if (factory.Surplus != null)
×
UNCOV
151
                {
×
UNCOV
152
                    foreach (var surplus in factory.Surplus)
×
UNCOV
153
                    {
×
UNCOV
154
                        if (surplus.Name == "Planning Note")
×
UNCOV
155
                        {
×
UNCOV
156
                            factoryIssues.Add(surplus.Building); // Using Building field to store the note text
×
UNCOV
157
                        }
×
UNCOV
158
                        else if (surplus.Name.StartsWith("Export to"))
×
UNCOV
159
                        {
×
UNCOV
160
                            factoryIssues.Add($"Exporting: {surplus.Name} - {surplus.Quantity:F2} per/min");
×
UNCOV
161
                        }
×
UNCOV
162
                        else if (surplus.Quantity > 0)
×
UNCOV
163
                        {
×
UNCOV
164
                            factoryIssues.Add($"Surplus: {surplus.Name} - {surplus.Quantity:F2} per/min");
×
UNCOV
165
                        }
×
UNCOV
166
                    }
×
UNCOV
167
                }
×
168

UNCOV
169
                report[factory.Name] = factoryIssues;
×
UNCOV
170
            }
×
171

UNCOV
172
            return report;
×
UNCOV
173
        }
×
174
    }
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc