Skip to content
Snippets Groups Projects
Commit 724800ff authored by Stefano Borini's avatar Stefano Borini
Browse files

Added CSVExtractor

parent aeec752f
No related branches found
No related tags found
1 merge request!47Aggregate old plugins under the "dummy" core plugin
This commit is part of merge request !47. Comments created here will be created in the context of that merge request.
from traits.api import String
from force_bdss.api import bundle_id, BaseDataSourceBundle
from .csv_extractor_model import CSVExtractorModel
from .csv_extractor_data_source import CSVExtractorDataSource
class CSVExtractorBundle(BaseDataSourceBundle):
id = String(bundle_id("enthought", "csv_extractor"))
name = String("CSV Extractor")
def create_model(self, model_data=None):
if model_data is None:
model_data = {}
return CSVExtractorModel(self, **model_data)
def create_data_source(self, application, model):
return CSVExtractorDataSource(self, application, model)
import csv
import numpy
from force_bdss.api import BaseDataSource
from force_bdss.api import DataSourceResult
class CSVExtractorDataSource(BaseDataSource):
def run(self, parameters):
with open(self.model.filename) as csvfile:
reader = csv.reader(csvfile)
for rowindex, row in enumerate(reader):
if rowindex < self.model.row:
continue
if rowindex == self.model.row:
return DataSourceResult(
originator=self,
value_types=[self.model.cuba_type],
values=numpy.array(
parameters.values[0]+float(
row[self.model.column])).reshape(1, 1)
)
return None
return None
from traits.api import Int, String
from force_bdss.api import BaseDataSourceModel
class CSVExtractorModel(BaseDataSourceModel):
filename = String()
row = Int()
column = Int()
cuba_type = String()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment