Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Parfenov <[email protected]>
  • Loading branch information
Andrey1994 committed Nov 2, 2020
1 parent 94aeca9 commit 0708287
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cpp-package/src/inc/board_shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class BoardShim
void release_session ();
/// get latest collected data, doesnt remove it from ringbuffer
double **get_current_board_data (int num_samples, int *num_data_points);
/// Get board id in case of PLAYBACK or STREAMING board
/// Get board id, for some boards can be different than provided (playback, streaming)
int get_board_id ();
/// get number of packages in ringbuffer
int get_board_data_count ();
Expand Down
4 changes: 2 additions & 2 deletions csharp-package/brainflow/brainflow/board_shim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ public bool is_prepared ()
}

///<summary>
/// Get Master board id in case of PLAYBACK or STREAMING board
/// Get Board Id, for some boards can be different than provided
///</summary>
/// <returns> Master board id </returns>
public int get_board_id()
public int get_board_id ()
{
return master_board_id;
}
Expand Down
6 changes: 3 additions & 3 deletions csharp-package/brainflow/eeg_metrics/eeg_metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ static void Main (string[] args)
BrainFlowInputParams input_params = new BrainFlowInputParams ();
int board_id = parse_args (args, input_params);
BoardShim board_shim = new BoardShim (board_id, input_params);
int sampling_rate = BoardShim.get_sampling_rate (board_shim.get_board_id());
int nfft = DataFilter.get_nearest_power_of_two(sampling_rate);
int[] eeg_channels = BoardShim.get_eeg_channels(board_shim.get_board_id());
int sampling_rate = BoardShim.get_sampling_rate (board_shim.get_board_id ());
int nfft = DataFilter.get_nearest_power_of_two (sampling_rate);
int[] eeg_channels = BoardShim.get_eeg_channels (board_shim.get_board_id ());

board_shim.prepare_session ();
board_shim.start_stream (3600);
Expand Down
13 changes: 7 additions & 6 deletions csharp-package/brainflow/eeg_metrics_ci/eeg_metrics_ci.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ static void Main (string[] args)
BrainFlowModelParams model_params = new BrainFlowModelParams (0,0);
int board_id = parse_args (args, input_params,model_params);
BoardShim board_shim = new BoardShim (board_id, input_params);
int sampling_rate = BoardShim.get_sampling_rate (board_shim.get_board_id());
int nfft = DataFilter.get_nearest_power_of_two(sampling_rate);
int[] eeg_channels = BoardShim.get_eeg_channels(board_shim.get_board_id());
int sampling_rate = BoardShim.get_sampling_rate (board_shim.get_board_id ());
int nfft = DataFilter.get_nearest_power_of_two (sampling_rate);
int[] eeg_channels = BoardShim.get_eeg_channels (board_shim.get_board_id ());

board_shim.prepare_session ();
board_shim.start_stream (3600);
Expand All @@ -31,7 +31,8 @@ static void Main (string[] args)
double[] feature_vector = bands.Item1.Concatenate (bands.Item2);
MLModel concentration = new MLModel (model_params);
concentration.prepare ();
Console.WriteLine (Enum.GetName(typeof(BrainFlowMetrics),model_params.metric) + " " + Enum.GetName(typeof(BrainFlowClassifiers),model_params.classifier) + " : " + concentration.predict (feature_vector));
Console.WriteLine (Enum.GetName (typeof (BrainFlowMetrics), model_params.metric) + " " + Enum.GetName (typeof (BrainFlowClassifiers), model_params.classifier) +
" : " + concentration.predict (feature_vector));
concentration.release ();
}

Expand Down Expand Up @@ -83,11 +84,11 @@ static int parse_args (string[] args, BrainFlowInputParams input_params, BrainF
}
if (args[i].Equals ("--metric"))
{
model_params.metric = Convert.ToInt32(args[i + 1]);
model_params.metric = Convert.ToInt32 (args[i + 1]);
}
if (args[i].Equals ("--classifier"))
{
model_params.classifier = Convert.ToInt32(args[i + 1]);
model_params.classifier = Convert.ToInt32 (args[i + 1]);
}
}
return board_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public void prepare_session () throws BrainFlowError
}

/**
* Get master board id incase of Playback or streaming board
* Get Board Id, can be different than provided (playback or streaming board)
*/
public int get_board_id ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static void main (String[] args) throws Exception
board_shim.prepare_session ();
board_shim.start_stream (3600);
BoardShim.log_message (LogLevels.LEVEL_INFO.get_code (), "Start sleeping in the main thread");
// recommended window size for eeg metric calculation is at least 4 seconds, bigger is better
// recommended window size for eeg metric calculation is at least 4 seconds,
// bigger is better
Thread.sleep (5000);
board_shim.stop_stream ();
double[][] data = board_shim.get_board_data ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static void main (String[] args) throws Exception
{
BoardShim.enable_board_logger ();
BrainFlowInputParams params = new BrainFlowInputParams ();
BrainFlowModelParams model_params = new BrainFlowModelParams (0,0);
int board_id = parse_args (args, params,model_params);
BrainFlowModelParams model_params = new BrainFlowModelParams (0, 0);
int board_id = parse_args (args, params, model_params);
BoardShim board_shim = new BoardShim (board_id, params);
int master_board_id = board_shim.get_board_id ();
int sampling_rate = BoardShim.get_sampling_rate (master_board_id);
Expand All @@ -30,7 +30,8 @@ public static void main (String[] args) throws Exception
board_shim.prepare_session ();
board_shim.start_stream (3600);
BoardShim.log_message (LogLevels.LEVEL_INFO.get_code (), "Start sleeping in the main thread");
// recommended window size for eeg metric calculation is at least 4 seconds, bigger is better
// recommended window size for eeg metric calculation is at least 4 seconds,
// bigger is better
Thread.sleep (5000);
board_shim.stop_stream ();
double[][] data = board_shim.get_board_data ();
Expand All @@ -40,11 +41,13 @@ public static void main (String[] args) throws Exception
double[] feature_vector = ArrayUtils.addAll (bands.getLeft (), bands.getRight ());
MLModel concentration = new MLModel (model_params);
concentration.prepare ();
System.out.println (BrainFlowMetrics.string_from_code(model_params.metric) + " " + BrainFlowClassifiers.string_from_code(model_params.classifier) + " : " + concentration.predict (feature_vector));
System.out.println (BrainFlowMetrics.string_from_code (model_params.metric) + " "
+ BrainFlowClassifiers.string_from_code (model_params.classifier) + " : "
+ concentration.predict (feature_vector));
concentration.release ();
}

private static int parse_args (String[] args, BrainFlowInputParams params,BrainFlowModelParams model_params)
private static int parse_args (String[] args, BrainFlowInputParams params, BrainFlowModelParams model_params)
{
int board_id = -1;
for (int i = 0; i < args.length; i++)
Expand Down Expand Up @@ -87,11 +90,11 @@ private static int parse_args (String[] args, BrainFlowInputParams params,BrainF
}
if (args[i].equals ("--metric"))
{
model_params.metric = Integer.parseInt(args[i + 1]);
model_params.metric = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--classifier"))
{
model_params.classifier = Integer.parseInt(args[i + 1]);
model_params.classifier = Integer.parseInt (args[i + 1]);
}
}
return board_id;
Expand Down
4 changes: 2 additions & 2 deletions python-package/brainflow/board_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,8 @@ def get_board_data_count (self) -> int:
raise BrainFlowError ('unable to obtain buffer size', res)
return data_size[0]

def get_board_id(self) -> int:
"""Get's the actual board id in case of playback or streaming board
def get_board_id (self) -> int:
"""Get's the actual board id, can be different than provided
:return: board id
:rtype: int
Expand Down
1 change: 0 additions & 1 deletion src/ml/train/focus_classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def main ():
test_brainflow_svm (data)
test_brainflow_lda (data)
else:
train_knn(data)
train_regression (data)
# Don't use grid search method unless you have to as it takes a while to complete
train_brainflow_search_svm (data) if args.grid_search else train_brainflow_svm (data)
Expand Down
3 changes: 2 additions & 1 deletion tests/cpp/ml_demo/src/eeg_metrics_ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ using namespace std::chrono;
bool parse_args (int argc, char *argv[], struct BrainFlowInputParams *params, int *board_id,
struct BrainFlowModelParams *model_params);


int main (int argc, char *argv[])
{
struct BrainFlowInputParams params;
struct BrainFlowModelParams model_params (0,0);
struct BrainFlowModelParams model_params (0, 0);
int board_id = 0;
if (!parse_args (argc, argv, &params, &board_id, &model_params))
{
Expand Down
5 changes: 3 additions & 2 deletions tests/python/eeg_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def main ():
params.ip_protocol = args.ip_protocol
params.timeout = args.timeout
params.file = args.file

board = BoardShim (args.board_id, params)
master_board_id = board.get_board_id()
sampling_rate = BoardShim.get_sampling_rate (int(master_board_id))
master_board_id = board.get_board_id ()
sampling_rate = BoardShim.get_sampling_rate (master_board_id)
board.prepare_session ()
board.start_stream (45000, args.streamer_params)
BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
Expand Down
5 changes: 3 additions & 2 deletions tests/python/eeg_metrics_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def main ():
params.ip_protocol = args.ip_protocol
params.timeout = args.timeout
params.file = args.file

board = BoardShim (args.board_id, params)
master_board_id = board.get_board_id()
sampling_rate = BoardShim.get_sampling_rate (int (master_board_id))
master_board_id = board.get_board_id ()
sampling_rate = BoardShim.get_sampling_rate (master_board_id)
board.prepare_session ()
board.start_stream (45000, args.streamer_params)
BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
Expand Down

0 comments on commit 0708287

Please sign in to comment.