private static void CalculateOpenReviews(long actualId, long[] simulationsIds, string path) { var result = new List <OpenReviewResult>(); foreach (var simulationId in simulationsIds) { var values = new List <int>(); var AppSettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "relationalgit.json"); var builder = new ConfigurationBuilder() .AddJsonFile(AppSettingsPath); var Configuration = builder.Build(); string connectionString = Configuration.GetConnectionString("RelationalGit"); using (SqlConnection connection = new SqlConnection(connectionString)) { var queryString = $@"SELECT NormalizedName, count(distinct(pullRequestId)) as pulls, DATEPART(QUARTER, DateTime) , DATEPART(year, Datetime) FROM [dbo].[DeveloperReviews] where SimulationId = @simId Group by DATEPART(QUARTER, Datetime) , NormalizedName, DATEPART(year, Datetime) order by pulls desc"; SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@simId", simulationId); connection.Open(); command.CommandTimeout = 0; SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { values.Add(Convert.ToInt32(reader["pulls"])); } } finally { // Always call Close when done reading. reader.Close(); } } using (var dbContext = GetDbContext()) { var lossSimulation = dbContext.LossSimulations.Single(q => q.Id == simulationId); var openRevResult = new OpenReviewResult() { LossSimulation = lossSimulation }; openRevResult.Results = values; result.Add(openRevResult); } } WriteOpenReviws(result, Path.Combine(path, "auc.csv")); }
private static void CalculateOpenReviews(long actualId, string path, string type) { var result = new List <OpenReviewResult>(); var values = new List <int>(); var AppSettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "relationalgit.json"); var builder = new ConfigurationBuilder() .AddJsonFile(AppSettingsPath); var Configuration = builder.Build(); string connectionString = Configuration.GetConnectionString("RelationalGit"); using (SqlConnection connection = new SqlConnection(connectionString)) { var queryString = ""; if (type == "quarter") { queryString = $@"SELECT NormalizedName, count(distinct(pullRequestId))as openreiews, DATEPART(QUARTER, DateTime) , DATEPART(year, Datetime) FROM [dbo].[DeveloperReviews] where SimulationId = @simId Group by DATEPART(QUARTER, Datetime) , NormalizedName, DATEPART(year, Datetime) order by openreiews desc"; } else if (type == "week") { queryString = $@"SELECT NormalizedName, count(distinct(pullRequestId))as openreiews, DATEPART(year, Datetime),DATEPART(month, DateTime) ,DATEPART(week, DateTime) FROM [dbo].[DeveloperReviews] where SimulationId = @simId Group by DATEPART(year, Datetime) , NormalizedName, DATEPART(month, Datetime), DATEPART(week, Datetime) order by openreiews desc"; } else if (type == "day") { queryString = $@"SELECT NormalizedName, avg(OpenReviews)as openreiews, DATEPART(MONTH, DateTime) , DATEPART(year, Datetime), DATEPART(day, Datetime) FROM [dbo].[DeveloperOpenReviews] where SimulationId = @simId Group by NormalizedName, DATEPART(MONTH, DateTime) , DATEPART(year, Datetime), DATEPART(day, Datetime) order by openreiews desc"; } else if (type == "month") { queryString = $@"SELECT NormalizedName, count(distinct(pullRequestId))as openreiews, DATEPART(year, Datetime),DATEPART(month, DateTime) FROM [dbo].[DeveloperReviews] where SimulationId = @simId Group by DATEPART(year, Datetime) , NormalizedName, DATEPART(month, Datetime), DATEPART(week, Datetime) order by openreiews desc"; } else if (type == "year") { queryString = $@"SELECT NormalizedName, count(distinct(pullRequestId))as openreiews, DATEPART(year, Datetime) FROM [dbo].[DeveloperReviews] where SimulationId = @simId Group by DATEPART(year, Datetime) , NormalizedName order by openreiews desc"; } SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@simId", actualId); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { values.Add(Convert.ToInt32(reader["openreiews"])); } } finally { // Always call Close when done reading. reader.Close(); } } using (var dbContext = GetDbContext()) { var lossSimulation = dbContext.LossSimulations.Single(q => q.Id == actualId); var openRevResult = new OpenReviewResult() { LossSimulation = lossSimulation }; openRevResult.Results = values; result.Add(openRevResult); } var csvName = "OpenreviewPer" + type + ".csv"; WriteOprnReviws(result, Path.Combine(path, csvName)); }