class UtilConfig(object): lang1 = related.ChildField(LanguageInfo) lang2 = related.ChildField(LanguageInfo) redo = related.BooleanField(default=False) path = related.StringField(default=".") num = related.IntegerField(default=10) record = related.BooleanField(default=True)
class BubbleChartSettings: linear_fit = related.BooleanField(False, key='linearFit') result_limit = related.IntegerField(100, key='resultLimit') show_legend = related.BooleanField(False, key='showLegend') x_axis = related.StringField('', key='xAxis') y_axis = related.StringField('', key='yAxis') z_axis = related.StringField('', key='zAxis')
class TableSettings: inverted_fields = related.SequenceField(str, [], key='invertedFields') table_format = related.ChildField(TableFormat, TableFormat.TABLE, key='tableFormat') enable_pagination = related.BooleanField(True, key='enablePagination') row_height = related.FloatField(30, key='rowHeight') add_total_row = related.BooleanField(False, key='addTotalRow') header_font_family = related.StringField( FONT_FAMILY_DEFAULT, key='headerFontFamily' ) header_color = related.StringField(FONT_COLOR_DEFAULT, key='headerColor') header_font_size = related.StringField(FONT_12, key='headerFontSize') header_background = related.StringField('#fff', key='headerBackground') header_border_color = related.StringField('#d9d9d9', key='headerBorderColor') row_font_family = related.StringField(FONT_FAMILY_DEFAULT, key='rowFontFamily') row_color = related.StringField(FONT_COLOR_DEFAULT, key='rowColor') row_font_size = related.StringField(FONT_12, key='rowFontSize') row_background = related.StringField('#fff', key='rowBackground') row_alternate_background = related.StringField( '#f0f0f0', key='rowAlternateBackground' ) row_border_color = related.StringField('#d9d9d9', key='rowBorderColor') footer_font_family = related.StringField( FONT_FAMILY_DEFAULT, key='footerFontFamily' ) footer_color = related.StringField(FONT_COLOR_DEFAULT, key='footerColor') footer_font_size = related.StringField(FONT_12, key='footerFontSize') footer_background = related.StringField('#fff', key='footerBackground') footer_border_color = related.StringField('#fff', key='footerBorderColor')
class CommandConfig(object): target_device_list = related.SequenceField(TargetDevice) database = related.ChildField(Database, required=False) influxdb = related.ChildField(Influxdb, required=False) set_measurement_interval = related.IntegerField(required=False) dry_run = related.BooleanField(default=False, required=False) no_scan = related.BooleanField(default=False, required=False)
class MapSettings: base_layer = related.ChildField(BaseMapLayer, BaseMapLayer.STREETS, key='baseLayer') current_display = related.StringField('dots', key='currentDisplay') map_center = related.ChildField(Coordinates, [0.0, 0.0], key='mapCenter') overlay_layers = related.SequenceField( str, DEFAULT_OVERLAY_LAYERS, key='overlayLayers' ) selected_field = related.StringField('', key='selectedField') selected_geo_tiles = related.StringField('', key='selectedGeoTiles') zoom_level = related.FloatField(1.0, key='zoomLevel') show_administrative_boundaries = related.BooleanField( True, key='showAdminBoundaries' ) show_labels = related.BooleanField(False, key='showLabels') fill_opacity = related.FloatField(0.8, key='fillOpacity') tooltip_font_color = related.StringField(FONT_COLOR_DEFAULT, key='tooltipFontColor') tooltip_font_family = related.StringField( FONT_FAMILY_DEFAULT, key='tooltipFontFamily' ) tooltip_font_size = related.StringField(FONT_12, key='tooltipFontSize') tooltip_bold = related.BooleanField(False, key='tooltipBold') # HACK(stephen, moriah): This setting is really poorly designed. It encodes # a color value + alpha as a dict instead of rgba or hex + alpha which can # be represented as a string. FIX THIS OR REMOVE IT. tooltip_background_color = related.ChildField( dict, DEFAULT_MAP_TOOLTIP_BACKGROUND, key='tooltipBackgroundColor' )
class EnvCreateArgs(RelatedConfigMixin): model = StrSequenceField(str, required=True) source = related.StringField(required=True) dataloader = StrSequenceField(str, default=[], required=False) env = related.StringField(default=None, required=False) gpu = related.BooleanField(default=False, required=False) tmpdir = related.StringField(default=None, required=False) vep = related.BooleanField(default=False, required=False)
class HeatTileSettings: divergent_coloration = related.BooleanField(True, key='divergentColoration') first_y_axis_selections = related.SequenceField(str, [], key='firstYaxisSelections') invert_coloration = related.BooleanField(False, key='invertColoration') log_scaling = related.BooleanField(True, key='logScaling') result_limit = related.IntegerField(100, key='resultLimit') selected_field = related.StringField('', key='selectedField') show_time_on_y_axis = related.BooleanField(True, key='showTimeOnYAxis') sort_order = related.ChildField(SortOrder, SortOrder.DESCENDING, key='sortOrder') sort_on = related.StringField('', key='sortOn') use_ethiopian_dates = related.BooleanField(False, key='useEthiopianDates')
class TimeSeriesSettings: bucket_mean = related.BooleanField(False, key='bucketMean') bucket_type = related.ChildField( TimeSeriesBucket, TimeSeriesBucket.MONTH, key='bucketType' ) log_scaling = related.BooleanField(False, key='logScaling') result_limit = related.IntegerField(5, key='resultLimit') sort_order = related.ChildField(SortOrder, SortOrder.DESCENDING, key='sortOrder') sort_on = related.StringField('', key='sortOn') use_ethiopian_dates = related.BooleanField(False, key='useEthiopianDates') show_data_labels = related.BooleanField(False, key='showDataLabels') rotate_labels = related.BooleanField(True, key='rotateLabels')
class LegendSettings(object): legend_font_color = related.StringField(FONT_COLOR_DEFAULT, key='legendFontColor') legend_font_family = related.StringField(FONT_FAMILY_DEFAULT, key='legendFontFamily') legend_font_size = related.StringField(FONT_16, key='legendFontSize') legend_placement = related.ChildField(LegendPlacement, LegendPlacement.BOTTOM, key='legendPlacement') overlap_legend_with_chart = related.BooleanField( False, key='overlapLegendWithChart') show_legend = related.BooleanField(True, key='showLegend')
class FilterPanelSettings: aggregation_levels = related.SequenceField(str, [], key='aggregationLevels') auto_update_granularity = related.BooleanField(False, key='autoUpdateGranularity') date_picker_type = related.StringField('CUSTOM', key='datePickerType') filter_panel_components = related.SequenceField( str, [], key='filterPanelComponents') enabled_filters = related.SequenceField(str, [], key='enabledFilters') initial_selected_components = related.SequenceField( str, [], key='initialSelectedComponents') show_dashboard_filterButton = related.BooleanField( False, key='showDashboardFilterButton')
class SeriesSettingsObject(object): id = related.StringField() color = related.StringField() data_label_font_size = related.StringField(FONT_12, key='dataLabelFontSize') data_label_format = related.StringField('0%', key='dataLabelFormat') is_visible = related.BooleanField(True, key='isVisible') label = related.StringField('Other') show_constituents = related.BooleanField(False, key='showConstituents') show_series_value = related.BooleanField(False, key='showSeriesValue') y_axis = related.ChildField(SeriesObjectAxis, SeriesObjectAxis.Y1_AXIS, key='yAxis')
class DataLoaderImport(RelatedConfigMixin): """Dataloader specification for the import """ defined_as = related.StringField() default_args = related.ChildField(dict, default=OrderedDict(), required=False) # specify also dataloader dependencies explicitly dependencies = related.ChildField(Dependencies, default=Dependencies(), required=False) # whether to parse the dependencies from the dataloader when installing it parse_dependencies = related.BooleanField(default=True, required=False) def get(self): """Get the dataloader """ from kipoi.data import BaseDataLoader from copy import deepcopy obj = load_obj(self.defined_as) # check that it inherits from BaseDataLoader if not inherits_from(obj, BaseDataLoader): raise ValueError("Dataloader: {} doen't inherit from kipoi.data.BaseDataLoader".format(self.defined_as)) # override the default arguments if self.default_args: obj = override_default_kwargs(obj, self.default_args) # override also the values in the example in case # they were previously specified for k, v in six.iteritems(self.default_args): if not isinstance(obj.args[k].example, UNSPECIFIED): obj.args[k].example = v return obj
class BarGraphSettings: result_limit = related.IntegerField(50, key='resultLimit') sort_order = related.ChildField(SortOrder, SortOrder.DESCENDING, key='sortOrder') sort_on = related.StringField('', key='sortOn') stack_bars = related.BooleanField(False, key='stackBars')
class Profile(object): name = related.StringField(default="__root__") host = related.StringField(required=False) schemas = related.ChildField(Namespace, required=False) globals = related.ChildField(Namespace, required=False) headers = related.ChildField(Namespace, required=False) prefixes = related.SequenceField(str, default=None) extensions = related.SequenceField(str, default=["rigor"]) includes = related.SequenceField(str, default=None) excludes = related.SequenceField(str, default=None) concurrency = related.IntegerField(default=5) retries = related.IntegerField(default=0) sleep = related.IntegerField(default=60) retry_failed = related.BooleanField(default=False, required=False) def __attrs_post_init__(self): # circumvent frozen error due to immutable extensions = [ ext[1:] if ext.startswith(".") else ext for ext in self.extensions or [] ] object.__setattr__(self, "extensions", extensions) def as_dict(self): kwargs = related.to_dict(self) kwargs.pop("profiles", None) kwargs.pop("file_path", None) return kwargs
class ExamQuestion: id = related.StringField(None) text = related.StringField('') is_multiple_choice = related.BooleanField(False) answers = related.SequenceField(ExamQuestionAnswer, None) points = related.IntegerField(0) @staticmethod def from_meta(id: str, meta: ExamQuestionMeta): meta.validate() multiple_choice = meta.is_multiple_choice answers_meta = meta.prepare_answers() answers = [ExamQuestionAnswer.from_meta(ans) for ans in answers_meta] return ExamQuestion(id=id, text=meta.text, is_multiple_choice=multiple_choice, answers=answers, points=meta.points) def grade(self, meta: ExamQuestionMeta) -> int: """ Returns the score for this ExamQuestion instance """ grader = get_grader(meta.grader) if grader: return grader(meta, self) return 0
class ScenarioResult(object): uuid = related.UUIDField() case = related.ChildField(Case, required=None) scenario = related.ChildField(Namespace, required=None) success = related.BooleanField(default=True) step_results = related.SequenceField(StepResult, default=[]) suite = related.ChildField(Suite, required=False)
class Fetch(object): url = related.StringField() method = related.StringField() kwargs = related.ChildField(dict) is_form = related.BooleanField() def get_kwargs(self, is_aiohttp): kw = self.kwargs.copy() data = kw.get("data", None) # aiohttp is different from requests in handling files # http://aiohttp.readthedocs.io/en/stable/client.html # http://docs.python-requests.org/en/master/user/quickstart files = kw.pop("files", None) if is_aiohttp else None if self.is_form: if isinstance(data, dict) and isinstance(files, dict): data.update(files) else: kw['data'] = related.to_json(data) # unlimited timeout if not specified kw.setdefault("timeout", None) # add verify = False for requests if not is_aiohttp: kw['verify'] = False return kw
class ExamQuestionAnswer: id = related.IntegerField(0) text = related.StringField('') is_selected = related.BooleanField(False, required=False) @staticmethod def from_meta(meta: ExamQuestionAnswerMeta): return ExamQuestionAnswer(id=meta.id, text=meta.text)
class Step(object): description = related.StringField() request = related.ChildField(Requestor) extract = related.ChildField(Namespace, default=Namespace()) iterate = related.ChildField(Iterator, default=Iterator()) validate = related.SequenceField(Validator, required=False) condition = related.BooleanField(required=False, default=None) transform = related.StringField(required=False, default=None) name = related.StringField(required=False, default=None) sleep = related.FloatField(required=False, default=0.01) retryable = related.BooleanField(required=False, default=False) def is_retryable(self): return self.is_get() or self.retryable def is_get(self): return self.request and self.request.method == Method.GET
class MyModel(object): is_for = related.StringField(key="for") criss = related.StringField(key="cross") cross = related.StringField(key="criss") is_not = related.BooleanField(key="not") is_list = related.SequenceField(str, key="list") is_type = related.ChildField(DataType, key="type") is_dict = related.MappingField(MyChild, "int", key="dict", required=False)
class Detector: type = related.StringField() config = related.ChildField(object, key="detectorConfig") enabled = related.BooleanField(default=True) trusted = related.BooleanField(default=False) training_interval = TimeDelta(default="0") last_updated = related.DateTimeField("%Y-%m-%d %H:%M:%S", required=False, key="lastUpdateTimestamp") uuid = related.StringField(required=False) created_by = related.StringField(required=False, key="createdBy") meta = related.ChildField(DetectorMeta, required=False) def train(self, data, *args, **kwargs): """ TODO: Add metadata boolean that tells if the detector needs training. """ raise NotImplementedError @property def minutes_since_created(self): if self.meta and self.meta.date_created: created_timedelta = (datetime.datetime.utcnow() - self.meta.date_created) return round(created_timedelta.total_seconds() / 60) @property def minutes_since_trained(self): if self.last_updated: trained_timedelta = (datetime.datetime.utcnow() - self.last_updated) return round(trained_timedelta.total_seconds() / 60) @property def needs_training(self): _needs_training = False training_interval_minutes = round( self.training_interval.total_seconds() / 60) if training_interval_minutes == 0: pass elif not self.uuid: _needs_training = True elif self.minutes_since_trained and self.minutes_since_trained > training_interval_minutes: _needs_training = True return _needs_training
class Step(object): description = related.StringField() request = related.ChildField(Requestor) extract = related.ChildField(Namespace, default=Namespace()) iterate = related.ChildField(Iterator, default=Iterator()) validate = related.SequenceField(Validator, required=False) condition = related.BooleanField(required=False, default=None) transform = related.StringField(required=False, default=None) name = related.StringField(required=False, default=None) sleep = related.FloatField(required=False, default=0.01)
class LayoutItem: id = related.StringField() query_id = related.StringField(key='queryId') item_type = related.ChildField(VisualizationType, key='type') upper_x = related.IntegerField(key='upperX') upper_y = related.IntegerField(key='upperY') size_id = related.StringField(key='sizeId') custom_fields = related.SequenceField(CustomField, [], key='customFields') # TODO(stephen, anyone): Add full model for filter modal selections and # frontend selections filter. filter_modal_selections = related.ChildField(dict, {}, key='filterModalSelections') front_end_selections_filter = related.ChildField( dict, {}, key='frontendSelectionsFilter' ) name = related.StringField(required=False) is_advanced_query_item = related.BooleanField(False, key='isAdvancedQueryItem') is_locked = related.BooleanField(False, key='isLocked') setting_id = related.StringField(required=False, key='settingId')
class ExamQuestionAnswerMeta: """ Represents metadata of a question answer's object """ text = related.StringField('') is_correct = related.BooleanField(False, required=False) likelihood = related.IntegerField(1, required=False) id = related.IntegerField(0) def __str__(self): return f"{self.id}: [{'+' if self.is_correct else '-'}] {self.text}"
class DetectorMapping: detector = related.ChildField(DetectorUUID) expression = related.ChildField(DetectorMappingExpression) user = related.ChildField(DetectorMappingUser) fields = related.SequenceField(str, required=False) id = related.StringField(required=False) last_modified_time_in_millis = related.IntegerField( required=False, key="lastModifiedTimeInMillis") created_time_in_millis = related.IntegerField(required=False, key="createdTimeInMillis") enabled = related.BooleanField(required=False)
class BumpChartSettings: result_limit = related.IntegerField(25, key='resultLimit') selected_field = related.StringField('', key='selectedField') # NOTE(stephen): This is a mapping from field ID to True. That is difficult # to represent with `related` and we'd prefer having a set on both the # frontend and the backend. Fix this. selected_keys = related.ChildField(dict, {}, key='selectedKeys') sort_order = related.ChildField(SortOrder, SortOrder.DESCENDING, key='sortOrder') theme = related.ChildField(BumpChartTheme, BumpChartTheme.DARK) use_ethiopian_dates = related.BooleanField(False, key='useEthiopianDates')
class Company(object): name = related.StringField() uuid = related.UUIDField() email = related.RegexField("[^@]+@[^@]+", required=False) is_active = related.BooleanField(required=False) url = related.URLField(required=False) meta = related.ChildField(dict, required=False) nicknames = related.SequenceField(str, required=False) temperature = related.FloatField(required=False) guess = related.SetField(int, required=False) established = related.DateField('%m/%d/%Y', required=False) closed = related.DateField(required=False) # default formatter (%Y-%m-%d)
class DataLoaderArgument(RelatedConfigMixin): # MAYBE - make this a general argument class doc = related.StringField("", required=False) example = AnyField(required=False) name = related.StringField(required=False) type = related.StringField(default='str', required=False) optional = related.BooleanField(default=False, required=False) tags = StrSequenceField(str, default=[], required=False) # TODO - restrict the tags def __attrs_post_init__(self): if self.doc == "": logger.warn("doc empty for one of the dataloader `args` fields")
class Operation(object): responses = related.MappingField(Response, "code", required=True) tags = related.SequenceField(str, required=False) summary = related.StringField(required=False) description = related.StringField(required=False) operationId = related.StringField(required=False) parameters = related.SequenceField(Parameter, required=False) consumes = related.SequenceField(MIMEType, required=False) produces = related.SequenceField(MIMEType, required=False) externalDocs = related.ChildField(dict, required=False) schemes = related.SequenceField(Scheme, required=False) deprecated = related.BooleanField(required=False) security = related.ChildField(dict, required=False)
class Exam: """Represents a writable exam""" meta_uuid = related.UUIDField() generated_at = related.DateTimeField(default=datetime.now(), required=False) questions = related.SequenceField(ExamQuestion, required=False) title = related.StringField('') description = related.StringField(required=False) was_user_completed = related.BooleanField(False, required=False) user_name = related.StringField(required=False) completed_at = related.DateTimeField(required=False) def save(self, path: str): with open(path, "w") as file: related.to_yaml(self, file) def clear(self): """ Clears this Exam instance from any user-input """ self.was_user_completed = False self.user_name = None self.completed_at = None for question in self.questions: for ans in question.answers: ans.is_selected = False @property def max_score(self): return sum(q.points for q in self.questions) def get_score(self, meta, question_callback: Callable = None) -> int: """ Calculates this Exam's total score. Args question_callback: called for each graded question with its score """ if meta is None: return 0 score = 0 for question in self.questions: question_meta = meta.find_question(question.id) points = question.grade(question_meta) if question_callback: question_callback(question, points) score += points return score