def push_student_responses_to_s3(_xmodule_instance_args, _entry_id, course_id, _task_input, action_name): """ For a given `course_id`, generate a responses CSV file for students that have submitted problem responses, and store using a `ReportStore`. Once created, the files can be accessed by instantiating another `ReportStore` (via `ReportStore.from_config()`) and calling `link_for()` on it. Writes are buffered, so we'll never write part of a CSV file to S3 -- i.e. any files that are visible in ReportStore will be complete ones. """ start_time = datetime.now(UTC) try: course = get_course_by_id(course_id) except ValueError as e: TASK_LOG.error(e.message) return "failed" rows = student_response_rows(course) # Generate parts of the file name timestamp_str = start_time.strftime("%Y-%m-%d-%H%M") course_id_prefix = course_filename_prefix_generator(course_id) # Perform the actual upload report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') report_store.store_rows( course_id, u"{course_id_prefix}_responses_report_{timestamp_str}.csv".format( course_id_prefix=course_id_prefix, timestamp_str=timestamp_str, ), rows) return "succeeded"
def upload_csv_to_report_store(rows, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'): """ Upload data as a CSV using ReportStore. Arguments: rows: CSV data in the following format (first column may be a header): [ [row1_colum1, row1_colum2, ...], ... ] csv_name: Name of the resulting CSV course_id: ID of the course Returns: report_name: string - Name of the generated report """ report_store = ReportStore.from_config(config_name) report_name = u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format( course_prefix=course_filename_prefix_generator(course_id), csv_name=csv_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")) report_store.store_rows(course_id, report_name, rows) report_path = report_store.storage.url( report_store.path_to(course_id, report_name)) tracker_emit(csv_name) return report_name, report_path
def upload_csv_to_report_store(rows, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'): """ Upload data as a CSV using ReportStore. Arguments: rows: CSV data in the following format (first column may be a header): [ [row1_colum1, row1_colum2, ...], ... ] csv_name: Name of the resulting CSV course_id: ID of the course """ report_store = ReportStore.from_config(config_name) report_store.store_rows( course_id, u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format( course_prefix=course_filename_prefix_generator(course_id), csv_name=csv_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M") ), rows ) tracker.emit(REPORT_REQUESTED_EVENT_NAME, {"report_type": csv_name, })
def _upload_exec_summary_to_store(data_dict, report_name, course_id, generated_at, config_name='FINANCIAL_REPORTS'): """ Upload Executive Summary Html file using ReportStore. Arguments: data_dict: containing executive report data. report_name: Name of the resulting Html File. course_id: ID of the course """ report_store = ReportStore.from_config(config_name) # Use the data dict and html template to generate the output buffer output_buffer = StringIO( render_to_string( "instructor/instructor_dashboard_2/executive_summary.html", data_dict)) report_store.store( course_id, u"{course_prefix}_{report_name}_{timestamp_str}.html".format( course_prefix=course_filename_prefix_generator(course_id), report_name=report_name, timestamp_str=generated_at.strftime("%Y-%m-%d-%H%M")), output_buffer, ) tracker_emit(report_name)
def upload_csv_to_report_store(rows, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'): report_store = ReportStore.from_config(config_name) report_name = u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format( course_prefix=course_filename_prefix_generator(course_id), csv_name=csv_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")) report_store.store_rows(course_id, report_name, rows) tracker_emit(csv_name) return report_name
def upload_zip_to_report_store(file, zip_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'): """ Upload given file buffer as a zip file using ReportStore. """ report_store = ReportStore.from_config(config_name) report_name = u"{course_prefix}_{zip_name}_{timestamp_str}.zip".format( course_prefix=course_filename_prefix_generator(course_id), zip_name=zip_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")) report_store.store(course_id, report_name, file) tracker_emit(zip_name) return report_name
def upload_csv_to_report_store(rows, csv_name, course_id, timestamp): """ Upload data as a CSV using ReportStore. Arguments: rows: CSV data in the following format (first column may be a header): [ [row1_colum1, row1_colum2, ...], ... ] csv_name: Name of the resulting CSV course_id: ID of the course """ report_store = ReportStore.from_config() report_store.store_rows( course_id, u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format( course_prefix=course_filename_prefix_generator(course_id), csv_name=csv_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")), rows)
def get_report_info(csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD'): """ Returns ReportStore and Report Name. Arguments: csv_name: Name of the resulting CSV course_id: ID of the course Returns: report_stroe: ReportStore - Instance of report store report_name: string - Name of the generated report """ report_store = ReportStore.from_config(config_name) report_name = u"{course_prefix}_{csv_name}_{timestamp_str}.csv".format( course_prefix=course_filename_prefix_generator(course_id), csv_name=csv_name, timestamp_str=timestamp.strftime("%Y-%m-%d-%H%M")) return report_store, report_name
def test_custom_separator(self, course_key_class): self.assertEqual( course_filename_prefix_generator(course_key_class(org='foo', course='bar', run='baz'), separator='-'), u'foo-bar-baz')
def test_locators(self, course_key_class): self.assertEqual( course_filename_prefix_generator( course_key_class(org='foo', course='bar', run='baz')), u'foo_bar_baz')
def test_custom_separator(self, course_key): self.assertEqual( course_filename_prefix_generator(course_key, separator='-'), u'foo-bar-baz')
def test_locators(self, course_key): self.assertEqual(course_filename_prefix_generator(course_key), u'foo_bar_baz')