array und tuple eingefügt für extrapunkte
This commit is contained in:
parent
78ca5f49c6
commit
c6fe8e3435
@ -33,10 +33,27 @@ namespace Project_Periodensystem.Controller
|
||||
// NEUE METHODE: DataManager statt direkt PeriodicTableData
|
||||
_elements = DataManager.LoadElements();
|
||||
Logger.Log($"Controller: {_elements.Count} Elemente erfolgreich geladen (via DataManager)");
|
||||
|
||||
// NEUE FEATURES demonstrieren:
|
||||
// Array-Operationen testen
|
||||
var symbols = GetAllSymbols();
|
||||
Logger.LogArray("Element-Symbole (erste 10)", symbols.Take(10).ToArray());
|
||||
|
||||
// Tuple-Operationen testen
|
||||
var (totalElements, uniqueSeries, avgWeight) = GetStatistics();
|
||||
Logger.LogTuple("Statistiken", $"Elemente: {totalElements}, Serien: {uniqueSeries}, Ø-Gewicht: {avgWeight:F2}");
|
||||
|
||||
// Extremwerte finden
|
||||
var (lightest, heaviest) = GetWeightExtremes();
|
||||
if (lightest != null && heaviest != null)
|
||||
{
|
||||
Logger.LogTuple("Gewichts-Extreme", $"Leichtestes: {lightest.Symbol} ({lightest.AtomicWeight}), Schwerstes: {heaviest.Symbol} ({heaviest.AtomicWeight})");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogException(ex, "LoadElements");
|
||||
Logger.Log($"EXCEPTION in LoadElements: {ex.Message}");
|
||||
_elements = new List<Element>();
|
||||
}
|
||||
}
|
||||
@ -50,6 +67,60 @@ namespace Project_Periodensystem.Controller
|
||||
return _elements;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt Elemente als Array zurück (für Array-Operationen)
|
||||
/// </summary>
|
||||
/// <returns>Array aller Elemente</returns>
|
||||
public Element[] GetAllElementsAsArray()
|
||||
{
|
||||
return _elements.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt nur die Symbole als String-Array zurück
|
||||
/// </summary>
|
||||
/// <returns>Array mit allen Element-Symbolen</returns>
|
||||
public string[] GetAllSymbols()
|
||||
{
|
||||
string[] symbols = new string[_elements.Count];
|
||||
for (int i = 0; i < _elements.Count; i++)
|
||||
{
|
||||
symbols[i] = _elements[i].Symbol;
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt Atomgewichte als Array zurück
|
||||
/// </summary>
|
||||
/// <returns>Array mit allen Atomgewichten</returns>
|
||||
public double[] GetAtomicWeights()
|
||||
{
|
||||
double[] weights = new double[_elements.Count];
|
||||
for (int i = 0; i < _elements.Count; i++)
|
||||
{
|
||||
weights[i] = _elements[i].AtomicWeight;
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Berechnet Durchschnittsgewicht aus Array
|
||||
/// </summary>
|
||||
/// <returns>Durchschnittliches Atomgewicht</returns>
|
||||
public double GetAverageAtomicWeight()
|
||||
{
|
||||
double[] weights = GetAtomicWeights();
|
||||
if (weights.Length == 0) return 0;
|
||||
|
||||
double sum = 0;
|
||||
for (int i = 0; i < weights.Length; i++)
|
||||
{
|
||||
sum += weights[i];
|
||||
}
|
||||
return sum / weights.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Speichert Elemente persistent (NEUE FUNKTION)
|
||||
/// </summary>
|
||||
@ -208,5 +279,72 @@ namespace Project_Periodensystem.Controller
|
||||
{
|
||||
return _elements.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt Element-Position als Tuple zurück
|
||||
/// </summary>
|
||||
/// <param name="atomicNumber">Atomnummer des Elements</param>
|
||||
/// <returns>Tuple mit (Row, Column) oder (-1, -1) wenn nicht gefunden</returns>
|
||||
public (int row, int column) GetElementPosition(int atomicNumber)
|
||||
{
|
||||
var element = GetElementByAtomicNumber(atomicNumber);
|
||||
if (element != null)
|
||||
{
|
||||
return (element.Row, element.Column);
|
||||
}
|
||||
return (-1, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt Grundinfos eines Elements als Tuple zurück
|
||||
/// </summary>
|
||||
/// <param name="atomicNumber">Atomnummer</param>
|
||||
/// <returns>Tuple mit (Symbol, Name, Gewicht)</returns>
|
||||
public (string symbol, string name, double weight) GetElementInfo(int atomicNumber)
|
||||
{
|
||||
var element = GetElementByAtomicNumber(atomicNumber);
|
||||
if (element != null)
|
||||
{
|
||||
return (element.Symbol, element.ElementName, element.AtomicWeight);
|
||||
}
|
||||
return ("", "Unbekannt", 0.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt Statistiken als Tuple zurück
|
||||
/// </summary>
|
||||
/// <returns>Tuple mit (Anzahl Elemente, Anzahl Serien, Durchschnittsgewicht)</returns>
|
||||
public (int totalElements, int uniqueSeries, double avgWeight) GetStatistics()
|
||||
{
|
||||
var seriesCount = GetAllSeries().Count;
|
||||
var avgWeight = GetAverageAtomicWeight();
|
||||
|
||||
return (_elements.Count, seriesCount, avgWeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Findet leichtestes und schwerstes Element
|
||||
/// </summary>
|
||||
/// <returns>Tuple mit (leichtestes Element, schwerstes Element)</returns>
|
||||
public (Element lightest, Element heaviest) GetWeightExtremes()
|
||||
{
|
||||
if (!_elements.Any())
|
||||
{
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
var lightest = _elements[0];
|
||||
var heaviest = _elements[0];
|
||||
|
||||
foreach (var element in _elements)
|
||||
{
|
||||
if (element.AtomicWeight < lightest.AtomicWeight)
|
||||
lightest = element;
|
||||
if (element.AtomicWeight > heaviest.AtomicWeight)
|
||||
heaviest = element;
|
||||
}
|
||||
|
||||
return (lightest, heaviest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Project_Periodensystem.Model
|
||||
{
|
||||
@ -132,5 +133,36 @@ namespace Project_Periodensystem.Model
|
||||
{
|
||||
return LogFilePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loggt ein Array von Strings
|
||||
/// </summary>
|
||||
/// <param name="title">Titel für das Array</param>
|
||||
/// <param name="items">Array von Items</param>
|
||||
public static void LogArray(string title, string[] items)
|
||||
{
|
||||
Log($"{title}: [{string.Join(", ", items)}]");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loggt ein Array von Zahlen
|
||||
/// </summary>
|
||||
/// <param name="title">Titel für das Array</param>
|
||||
/// <param name="numbers">Array von Zahlen</param>
|
||||
public static void LogArray(string title, double[] numbers)
|
||||
{
|
||||
var formattedNumbers = numbers.Select(n => n.ToString("F2")).ToArray();
|
||||
Log($"{title}: [{string.Join(", ", formattedNumbers)}]");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loggt Tuple-Informationen
|
||||
/// </summary>
|
||||
/// <param name="title">Titel</param>
|
||||
/// <param name="tupleInfo">Tuple als string</param>
|
||||
public static void LogTuple(string title, string tupleInfo)
|
||||
{
|
||||
Log($"{title}: {tupleInfo}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user