Sync up with changes from ARM64

This commit is contained in:
2025-05-01 14:08:33 -04:00
parent 148c236af2
commit c0384feb95
40 changed files with 494 additions and 365 deletions

View File

@@ -42,10 +42,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static List<DateTime> GetIncomeStatementDates(String symbol,IncomeStatement.PeriodType periodType)
{
List<DateTime> incomeStatementDates = new List<DateTime>();
@@ -80,10 +81,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static DateTime? GetLatestIncomeStatementDate(String symbol,IncomeStatement.PeriodType periodType)
{
MySqlConnection sqlConnection = null;
@@ -118,10 +120,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static IncomeStatement GetIncomeStatement(String symbol,IncomeStatement.PeriodType periodType)
{
MySqlConnection sqlConnection = null;
@@ -170,12 +173,14 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static TimeSeriesCollection GetRevenue(String symbol,IncomeStatement.PeriodType period)
{
Profiler profiler = new Profiler();
TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();
MySqlConnection sqlConnection = null;
MySqlDataReader sqlDataReader = null;
@@ -212,10 +217,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
// Profit Margin is calculated as a percentage.
public static TimeSeriesCollection GetProfitMargin(String symbol,IncomeStatement.PeriodType period=IncomeStatement.PeriodType.Annual)
{
@@ -260,14 +266,14 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
// Profit Margin is calculated as a percentage.
public static TimeSeriesCollection GetProfitMarginMaxAsOf(String symbol,DateTime maxDate, IncomeStatement.PeriodType period = IncomeStatement.PeriodType.Annual)
public static Dictionary<String,TimeSeriesCollection> GetProfitMarginMaxAsOf(List<String> symbols, DateTime maxDate,int maxSeries,IncomeStatement.PeriodType period = IncomeStatement.PeriodType.Annual)
{
TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();
Dictionary<String,TimeSeriesCollection> timeSeriesCollection = new Dictionary<String,TimeSeriesCollection>();
MySqlConnection sqlConnection = null;
MySqlDataReader sqlDataReader = null;
MySqlCommand sqlCommand = null;
@@ -277,9 +283,11 @@ namespace MarketData.DataAccess
{
StringBuilder sb = new StringBuilder();
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sb.Append("select symbol,asof,total_revenue,gross_profit from incomestatement where symbol='").Append(symbol).Append("'").Append(" ");
sb.Append(" and asof<='").Append(SqlUtils.SqlDate(maxDate)).Append("' ");
sb.Append(" and period=").Append(period.Equals(IncomeStatement.PeriodType.Annual) ? 0 : 1).Append(" order by asof desc;");
sb.Append("SELECT B.symbol, B.asof, B.total_revenue, B.gross_profit FROM ");
sb.Append("(SELECT symbol, asof, total_revenue, gross_profit, period , ROW_NUMBER() OVER(PARTITION BY symbol ORDER BY asof desc) AS rownum FROM incomestatement ");
sb.Append($" WHERE symbol IN {SqlUtils.CreateInClause(symbols)} AND asof<={SqlUtils.ToSqlDate(maxDate.Date,true)}");
sb.Append($" AND period={(period.Equals(IncomeStatement.PeriodType.Annual) ? 0 : 1)} )B ");
sb.Append($" WHERE B.rownum<={maxSeries} ");
strQuery = sb.ToString();
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
@@ -289,15 +297,19 @@ namespace MarketData.DataAccess
TimeSeriesElement timeSeriesElement = new TimeSeriesElement();
timeSeriesElement.Symbol = sqlDataReader.GetString(0);
timeSeriesElement.AsOf = sqlDataReader.GetDateTime(1);
timeSeriesElement.Type = period.Equals(IncomeStatement.PeriodType.Quarterly) ? TimeSeriesElement.ElementType.QuarterlyRevenue : TimeSeriesElement.ElementType.Revenue;
timeSeriesElement.Type = TimeSeriesElement.ElementType.OTHER;
timeSeriesElement.OtherType = "Profit Margin %";
if (sqlDataReader.IsDBNull(2)) continue;
double total_revenue = sqlDataReader.GetDouble(2);
if (sqlDataReader.IsDBNull(3)) continue;
double gross_profit = sqlDataReader.GetDouble(3);
if (0 == gross_profit) continue;
timeSeriesElement.Value = (gross_profit / total_revenue) * 100.00;
timeSeriesCollection.Add(timeSeriesElement);
if(!timeSeriesCollection.ContainsKey(timeSeriesElement.Symbol))
{
timeSeriesCollection.Add(timeSeriesElement.Symbol, new TimeSeriesCollection());
}
timeSeriesCollection[timeSeriesElement.Symbol].Add(timeSeriesElement);
}
return timeSeriesCollection;
}
@@ -309,10 +321,11 @@ namespace MarketData.DataAccess
finally
{
if (null != sqlCommand) sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
}
public static IncomeStatement GetIncomeStatement(String symbol,DateTime asof,IncomeStatement.PeriodType periodType)
{
MySqlConnection sqlConnection = null;
@@ -359,10 +372,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static IncomeStatement GetIncomeStatementMaxAsOf(String symbol,DateTime asof,IncomeStatement.PeriodType periodType)
{
MySqlConnection sqlConnection = null;
@@ -410,10 +424,11 @@ namespace MarketData.DataAccess
finally
{
if(null!=sqlCommand)sqlCommand.Dispose();
if (null != sqlDataReader) sqlDataReader.Close();
if (null != sqlDataReader) {sqlDataReader.Close();sqlDataReader.Dispose();}
if (null != sqlConnection) sqlConnection.Close();
}
}
public static bool InsertIncomeStatements(List<IncomeStatement> incomeStatements)
{
MySqlConnection sqlConnection = null;
@@ -480,6 +495,7 @@ namespace MarketData.DataAccess
if (null != sqlConnection) sqlConnection.Close();
}
}
private static bool DeleteIncomeStatements(List<IncomeStatement> incomeStatements, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction)
{
for (int index = 0; index < incomeStatements.Count; index++)
@@ -488,6 +504,7 @@ namespace MarketData.DataAccess
}
return true;
}
private static bool DeleteIncomeStatement(IncomeStatement incomeStatement, MySqlConnection sqlConnection, MySqlTransaction sqlTransaction)
{
StringBuilder sb = new StringBuilder();