119 lines
4.5 KiB
C#
119 lines
4.5 KiB
C#
using Python.Runtime;
|
|
using System.ComponentModel;
|
|
using System.Text.Json;
|
|
|
|
namespace dopt.DeltaBarth
|
|
{
|
|
public enum StatusCodes
|
|
{
|
|
[Description("Keine Fehler aufgetreten")]
|
|
Erfolg = 0,
|
|
[Description("Bei der Verbindung zum API-Server kam es zum Timeout")]
|
|
VerbindungTimeout = 1,
|
|
[Description("Bei der Verbindung zum API-Server ist ein Fehler aufgetreten")]
|
|
VerbindungFehler = 2,
|
|
[Description("Der bereitgestellte Datensatz enthält in Summe zu wenige Einzeleinträge")]
|
|
DatensatzZuWenigeDatenpunkte = 3,
|
|
[Description("Der bereitgestellte Datensatz enthält nach Aggregation zu Monaten zu wenig Einträge")]
|
|
DatensatzZuWenigeMonatsdatenpunkte = 4,
|
|
[Description("Die Prognosequalität des Modells erfüllt nicht ide Mindestanforderungen")]
|
|
KeineVerlaesslichePrognose = 5,
|
|
[Description("Vom API-Server wurde eine Fehlermeldung zurückgegeben")]
|
|
ApiServerFehler = 400,
|
|
}
|
|
public class PythonParsingException : Exception
|
|
{
|
|
public PythonParsingException() { }
|
|
public PythonParsingException(string message) : base(message) { }
|
|
}
|
|
public class Plugin : SharpPython.BasePlugin
|
|
{
|
|
protected dynamic pyModManagement;
|
|
protected dynamic pyModPipeline;
|
|
public Plugin(string runtimePath) : base(runtimePath: runtimePath, verbose: false)
|
|
{
|
|
base.Initialise();
|
|
using (Py.GIL())
|
|
{
|
|
pyModManagement = Py.Import("delta_barth.management");
|
|
pyModPipeline = Py.Import("delta_barth.pipelines");
|
|
}
|
|
}
|
|
public void Startup(string datenPfad, string basisApiUrl, string nutzername, string passwort, string datenbank, string mandant)
|
|
{
|
|
AssertNotDisposed();
|
|
Setup(datenPfad, basisApiUrl);
|
|
SetzeNutzerdaten(nutzername, passwort, datenbank, mandant);
|
|
}
|
|
public void SetzeNutzerdaten(string nutzername, string passwort, string datenbank, string mandant)
|
|
{
|
|
AssertNotDisposed();
|
|
using (Py.GIL()) {
|
|
pyModManagement.set_credentials(nutzername, passwort, datenbank, mandant);
|
|
}
|
|
}
|
|
public DataObjects.UmsatzPrognoseAusgabe UmsatzprognoseDummy(int? firmaId, DateTime? analyseBeginn)
|
|
{
|
|
AssertNotDisposed();
|
|
string pyJson;
|
|
using (Py.GIL())
|
|
{
|
|
pyJson = pyModPipeline.pipeline_sales_forecast_dummy(firmaId, analyseBeginn);
|
|
}
|
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseAusgabe>(pyJson) ?? throw new PythonParsingException("Could not correctly parse object from Python");
|
|
return parsed;
|
|
}
|
|
public DataObjects.UmsatzPrognoseAusgabe Umsatzprognose(int? firmaId, DateTime? analyseBeginn)
|
|
{
|
|
AssertNotDisposed();
|
|
string pyJson;
|
|
using (Py.GIL())
|
|
{
|
|
pyJson = pyModPipeline.pipeline_sales_forecast(firmaId, analyseBeginn);
|
|
}
|
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseAusgabe>(pyJson) ?? throw new PythonParsingException("Could not correctly parse object from Python");
|
|
return parsed;
|
|
}
|
|
protected void Setup(string datenPfad, string basisApiUrl)
|
|
{
|
|
AssertNotDisposed();
|
|
using (Py.GIL())
|
|
{
|
|
pyModManagement.setup(datenPfad, basisApiUrl);
|
|
}
|
|
}
|
|
protected string GetBaseApiUrl()
|
|
{
|
|
AssertNotDisposed();
|
|
string pyJson;
|
|
using (Py.GIL())
|
|
{
|
|
pyJson = (string)pyModManagement.get_base_url();
|
|
}
|
|
return pyJson;
|
|
}
|
|
protected string GetDataPath()
|
|
{
|
|
AssertNotDisposed();
|
|
string pyJson;
|
|
using (Py.GIL())
|
|
{
|
|
pyJson = (string)pyModManagement.get_data_path();
|
|
}
|
|
return pyJson;
|
|
}
|
|
protected DataObjects.Credentials GetCredentials()
|
|
{
|
|
AssertNotDisposed();
|
|
string pyJson;
|
|
using (Py.GIL())
|
|
{
|
|
pyJson = (string)pyModManagement.get_credentials();
|
|
}
|
|
|
|
DataObjects.Credentials? parsed = JsonSerializer.Deserialize<DataObjects.Credentials>(pyJson);
|
|
return parsed ?? throw new PythonParsingException("Could not correctly parse object from Python");
|
|
}
|
|
}
|
|
}
|