def to_internal_value(self, data): question = self.get_question() polling = question.polling now = _djtz.localtime(timezone=_djtz.get_default_timezone()) if now < polling.start_time: self.fail('polling_not_started') if polling.start_time + polling.duration <= now: self.fail('polling_ended') data = super().to_internal_value(data) data['question'] = question data = F.select_values(F.complement(F.isnone), data) logger.debug('QuestionAnswerSerializer.to_internal_value(%r)', data) if isinstance(question, models.TextQuestion): kwargs = F.project(data, 'guest_id question text'.split()) rest = F.project(data, F.without(data, *kwargs.keys())) elif isinstance(question, models.ChoiceQuestion): kwargs = F.project(data, 'guest_id question choices'.split()) rest = F.project(data, F.without(data, *kwargs.keys())) else: self.fail('unknown_question', question=question) if rest: self.fail('unknown_fields', fields=dict(rest)) return data
def get_samples_columns(samples): preferred = [ 'id', 'description', 'characteristics_ch1', 'characteristics_ch2' ] exclude = ['attrs', 'supplementary_file', 'geo_accession'] columns = distinct(icat(s.keys() for s in samples)) return lift(preferred, without(columns, *exclude))
def _create_header(self, header_add): """ Creates the header including the initial header and the header_add. :param header_add: List of strings found from the table to add to the initial_header. """ header = self._initial_header + header_add header[9] = 'Home' header.insert(11, 'WinLoss') return without(header, 'FGP', 'FTP', 'TPP')
def export(request, analysis_id): analysis = get_object_or_404(Analysis, pk=analysis_id) qs = MetaAnalysis.objects.filter(analysis=analysis) fieldnames = without([f.name for f in MetaAnalysis._meta.fields], 'id', 'analysis') csv = qs.to_dataframe(fieldnames, index='mygene_sym').to_csv() response = HttpResponse(csv, content_type='text/plain') filename = re.sub(r'\W+', '-', analysis.analysis_name) response[ 'Content-Disposition'] = 'attachment; filename="%s.csv"' % filename return response
def _get_file_path(kwargs): from dvc.dvcfile import DVC_FILE, DVC_FILE_SUFFIX out = first( concat( kwargs.get("outs", []), kwargs.get("outs_no_cache", []), kwargs.get("metrics", []), kwargs.get("metrics_no_cache", []), kwargs.get("plots", []), kwargs.get("plots_no_cache", []), kwargs.get("outs_persist", []), kwargs.get("outs_persist_no_cache", []), kwargs.get("checkpoints", []), without([kwargs.get("live", None)], None), )) return (os.path.basename(os.path.normpath(out)) + DVC_FILE_SUFFIX if out else DVC_FILE)
def lift(preferred, seq): return [col for col in preferred if col in seq] + without(seq, *preferred)
def fetch_annotation_data(series_id, platform_id=None, blind=['id']): samples = fetch_samples(series_id, platform_id) samples = remove_constant_fields(samples) columns = without(get_samples_columns(samples), *blind) return samples, columns