File Storage.cs
has 546 lines of code (exceeds 250 allowed). Consider refactoring.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Method ProcessLogEntry
has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring.
private void ProcessLogEntry(JournalOperation opCode, JObject logObject)
{
switch (opCode)
{
case JournalOperation.CreateStudy:
Method ProcessLogEntry
has 139 lines of code (exceeds 25 allowed). Consider refactoring.
private void ProcessLogEntry(JournalOperation opCode, JObject logObject)
{
switch (opCode)
{
case JournalOperation.CreateStudy:
Class JournalStorage
has 35 methods (exceeds 20 allowed). Consider refactoring.
public class JournalStorage : IOptunaStorage
{
private readonly Dictionary<int, Study.Study> _studies = new Dictionary<int, Study.Study>();
private readonly Dictionary<int, Trial.Trial> _trialCache = new Dictionary<int, Trial.Trial>();
private readonly Dictionary<string, int> _studyNameToIdIndex = new Dictionary<string, int>();
Method LoadDataFromFile
has 29 lines of code (exceeds 25 allowed). Consider refactoring.
private void LoadDataFromFile()
{
const int BufferSize = 65536;
var jsonBatch = new List<string>(1000);
Similar blocks of code found in 2 locations. Consider refactoring.
case JournalOperation.SetStudySystemAttr:
{
int studyId = (int)logObject["study_id"];
var systemAttr = (JObject)logObject["system_attr"];
foreach (KeyValuePair<string, JToken> item in systemAttr)
Similar blocks of code found in 2 locations. Consider refactoring.
case JournalOperation.SetStudyUserAttr:
{
int studyId = (int)logObject["study_id"];
var userAttr = (JObject)logObject["user_attr"];
foreach (KeyValuePair<string, JToken> item in userAttr)
Similar blocks of code found in 2 locations. Consider refactoring.
private void SetTrialSystemAttrFromJObject(int trialId, JObject systemAttr)
{
foreach (KeyValuePair<string, JToken> item in systemAttr)
{
string[] values = item.Value.Select(v => v.ToString()).ToArray();
Similar blocks of code found in 2 locations. Consider refactoring.
private void SetTrialUserAttrFromJObject(int trialId, JObject userAttr)
{
foreach (KeyValuePair<string, JToken> item in userAttr)
{
string[] values = item.Value.Select(v => v.ToString()).ToArray();
Similar blocks of code found in 3 locations. Consider refactoring.
public Dictionary<string, object> GetTrialUserAttrs(int trialId)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Similar blocks of code found in 3 locations. Consider refactoring.
public Dictionary<string, object> GetTrialParams(int trialId)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Similar blocks of code found in 3 locations. Consider refactoring.
public Dictionary<string, object> GetTrialSystemAttrs(int trialId)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Identical blocks of code found in 2 locations. Consider refactoring.
if (directions[0] == StudyDirection.Maximize)
{
return allTrials.OrderByDescending(trial => trial.Values[0]).First();
}
else
Similar blocks of code found in 4 locations. Consider refactoring.
public void SetTrialUserAttr(int trialId, string key, object value)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Similar blocks of code found in 4 locations. Consider refactoring.
public void SetTrialSystemAttr(int trialId, string key, object value)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Similar blocks of code found in 4 locations. Consider refactoring.
public void SetStudyUserAttr(int studyId, string key, object value)
{
EnsureInitialized();
if (!_studies.TryGetValue(studyId, out Study.Study study))
Similar blocks of code found in 4 locations. Consider refactoring.
public void SetStudySystemAttr(int studyId, string key, object value)
{
EnsureInitialized();
if (!_studies.TryGetValue(studyId, out Study.Study study))
Similar blocks of code found in 2 locations. Consider refactoring.
public Dictionary<string, object> GetStudyUserAttrs(int studyId)
{
EnsureInitialized();
if (!_studies.TryGetValue(studyId, out Study.Study study))
Similar blocks of code found in 2 locations. Consider refactoring.
public Dictionary<string, object> GetStudySystemAttrs(int studyId)
{
EnsureInitialized();
if (!_studies.TryGetValue(studyId, out Study.Study study))
Similar blocks of code found in 2 locations. Consider refactoring.
public int GetTrialNumberFromId(int trialId)
{
EnsureInitialized();
if (!_trialCache.TryGetValue(trialId, out Trial.Trial trial))
Similar blocks of code found in 2 locations. Consider refactoring.
public string GetStudyNameFromId(int studyId)
{
EnsureInitialized();
if (!_studies.TryGetValue(studyId, out Study.Study study))
Similar blocks of code found in 2 locations. Consider refactoring.
case JournalOperation.SetTrialSystemAttr:
{
int trialId = (int)logObject["trial_id"];
var systemAttr = (JObject)logObject["system_attr"];
SetTrialSystemAttrFromJObject(trialId, systemAttr);
Similar blocks of code found in 2 locations. Consider refactoring.
case JournalOperation.SetTrialUserAttr:
{
int trialId = (int)logObject["trial_id"];
var userAttr = (JObject)logObject["user_attr"];
SetTrialUserAttrFromJObject(trialId, userAttr);
There are no issues that match your filters.