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

samsmithnz / SatisfactoryTree / 17901390351

22 Sep 2025 12:51AM UTC coverage: 68.078% (+0.3%) from 67.811%
17901390351

push

github

web-flow
Merge pull request #310 from samsmithnz/FixingImportsAgain

Added new imported item type

427 of 736 branches covered (58.02%)

Branch coverage included in aggregate %.

91 of 185 new or added lines in 10 files covered. (49.19%)

7 existing lines in 3 files now uncovered.

1149 of 1579 relevant lines covered (72.77%)

1172.07 hits per line

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

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

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

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

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

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

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

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

64
                    double requestedQuantity = importedItem.Item.Quantity;
2✔
65
                    double availableQuantity = exportedItem.PartQuantityExported;
2✔
66

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

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

100
    }
101
}
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