CSV file that lists all student answers to the problem - openedx

As I followed the steps to download CSV of problem responses for a problem, It says “The problem responses report is being created. To view the status of the report, see Pending Tasks below.”
But, I am not seeing any pending tasks nor the files are being generated. Can’t see the generated file even after refreshing.
But, I can generate other CSV files for example, Problem Grade Report.
The issue is only for the problem response report.
PS: When I checked Admin, I could see that the request was failed with this error:
{"exception": "AssertionError", "traceback": "Traceback (most recent call last):\n File \"/openedx/venv/local/lib/python2.7/site-packages/celery/app/trace.py\", line 240, in trace_task\n R = retval = fun(*args, **kwargs)\n File \"/openedx/venv/local/lib/python2.7/site-packages/celery/app/trace.py\", line 438, in __protected_call__\n return self.run(*args, **kwargs)\n File \"/openedx/edx-platform/lms/djangoapps/instructor_task/tasks.py\", line 171, in calculate_problem_responses_csv\n return run_main_task(entry_id, task_fn, action_name)\n File \"/openedx/edx-platform/lms/djangoapps/instructor_task/tasks_helper/runner.py\", line 111, in run_main_task\n task_progress = task_fcn(entry_id, course_id, task_input, action_name)\n File \"/openedx/edx-platform/lms/djangoapps/instructor_task/tasks_helper/grades.py\", line 737, in generate\n usage_key_str=problem_location\n File \"/openedx/edx-platform/lms/djangoapps/instructor_task/tasks_helper/grades.py\", line 674, ...", "message": ""}
Please help.

After having much tries I was able to figure out my issue was caused because one operation which is not quite preferable by Open Edx. It is changing correct answer of a problem after few students submitting their responses. I was able to get their grades calculated based on new answers by using the Re-score option but unable to generate this report.
I will update here if I get a solution.

Related

Retrieving SwissProt from ExPASy server - error

I've just started learning my way around Biopython and I'm trying to use ExPASy to retrieve SwissProt records, just like described in page 180 of the Biopython tutorial (http://biopython.org/DIST/docs/tutorial/Tutorial.pdf), but also in a relevant ROSALIND exercise (http://rosalind.info/problems/dbpr/ - click to expand the "Programming shortcut" section).
The code I'm using is basically the same as in the ROSALIND exercise:
from Bio import ExPASy
from Bio import SwissProt
handle = ExPASy.get_sprot_raw('Q5SLP9')
record = SwissProt.read(handle)
However, the SwissProt.read function gives the following error messages (I've trimmed some of the filepaths):
Traceback (most recent call last): File "code.py", line 4, in <module>
record = SwissProt.read(handle) File "lib\site-packages\Bio\SwissProt\__init__.py", line 151, in read
record = _read(handle) File "lib\site-packages\Bio\SwissProt\__init__.py", line 255, in _read
_read_ft(record, line) File "lib\site-packages\Bio\SwissProt\__init__.py", line 594, in _read_ft
assert not from_res and not to_res, line AssertionError: /note="Single-stranded DNA-binding protein"
I found this has been reported in GitHub (https://github.com/biopython/biopython/issues/2417), so I'm not the first one who gets this, but I don't really find any updated version of the package or any way to fix the issue. Maybe it's because I'm very new to using packages. Could someone help me please?
Please update your BioPython to version 1.77. The issue has been fixed with pull request 2484.

SeqIO.parse throwing error in genbank files

I'm working with some genbank seq files and have the following code:
for seq_record in SeqIO.parse("datafile_location, "genbank"):
And while it can run through most of the seqs in the seq file (which contains multiple seqs) I get the following error. Any thoughts about how to fix this?
Maybe delete the offending seq? It gets to record 92126 of 93145 and then throws the error.
I have tried re-downloading the seq file, but that doesn't fix the problem.
File "C:\python38\lib\site-packages\Bio\GenBank\Scanner.py", line 516,
in parse_records record = self.parse(handle, do_features) File
"C:\python38\lib\site-packages\Bio\GenBank\Scanner.py", line 499, in
parse if self.feed(handle, consumer, do_features): File
"C:\python38\lib\site-packages\Bio\GenBank\Scanner.py", line 466, in
feed self._feed_header_lines(consumer, self.parse_header()) File
"C:\python38\lib\site-packages\Bio\GenBank\Scanner.py", line 1801, in
feed_header_lines previous_value_line = structured_comment_dict[ KeyError: 'Assembly-Data'
Seems similar like BioPython issue #2844.
A pull request was recently merged to address this.

Flask: How do I successfully use multiprocessing (not multithreading)?

I am using a Flask server to handle requests for some image-processing tasks.
The processing relies extensively on OpenCV and I would now like to trivially-parallelize some of the slower steps.
I have a preference for multiprocessing rather than multithreading (please assume the former in your answers).
But multiprocessing with opencv is apparently broken (I am on Python 2.7 + macOS): https://github.com/opencv/opencv/issues/5150
One solution (see https://github.com/opencv/opencv/issues/5150#issuecomment-400727184) is to use the excellent Loky (https://github.com/tomMoral/loky)
[Question: What other working solutions exist apart from concurrent.futures, loky, joblib..?]
But Loky leads me to the following stacktrace:
a,b = f.result()
File "/anaconda2/lib/python2.7/site-packages/loky/_base.py", line 433, in result
return self.__get_result()
File "/anaconda2/lib/python2.7/site-packages/loky/_base.py", line 381, in __get_result
raise self._exception
BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
This was caused directly by
'''
Traceback (most recent call last):
File "/anaconda2/lib/python2.7/site-packages/loky/process_executor.py", line 391, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "/anaconda2/lib/python2.7/multiprocessing/queues.py", line 135, in get
res = self._recv()
File "myfile.py", line 44, in <module>
app.config['EXECUTOR_MAX_WORKERS'] = 5
File "/anaconda2/lib/python2.7/site-packages/werkzeug/local.py", line 348, in __getattr__
return getattr(self._get_current_object(), name)
File "/anaconda2/lib/python2.7/site-packages/werkzeug/local.py", line 307, in _get_current_object
return self.__local()
File "/anaconda2/lib/python2.7/site-packages/flask/globals.py", line 52, in _find_app
raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this, set up an application context with app.app_context(). See the
documentation for more information.
'''
The functions to be parallelized are not being called from app/main.py, but rather from an abitrarily-deep submodule.
I have tried the similarly-useful-looking https://flask-executor.readthedocs.io/en/latest, also so far in vain.
So the question is:
How can I safely pass the application context through to the workers or otherwise get multiprocessing working (without recourse to multithreading)?
I can build out this question if you need more information. Many thanks as ever.
Related resources:
Copy flask request/app context to another process
Flask Multiprocessing
Update:
Non-opencv calls work fine with flask-executor (no Loky) :)
The problem comes when trying to call an opencv function like knnMatch.
If Loky fixes the opencv issue, I wonder if it can be made to work with flask-executor (not for me, so far).

is it possible to catch 404 error without exit run in python?

I want to download a bunch of url list by:
urllib.request.urlretrieve(url, filename)
but sadly, few links are broken. and when urlretrieve meets that broken link
Traceback (most recent call last):
File "D:/Users/hyungsoo/PycharmProjects/untitled/check.py", line 71, in <module>
....blah_blah....
urllib.error.HTTPError: HTTP Error 404: Not Found
give me this error sign and program exited.
how to pass the broken url?
and moreover, is it possible to program tells me what link is broken?
You could try a "try...except..." statement, which you may find helpful. The "try" portion will attempt the given code, but the
"except" portion will be ready for the error message. It is really a wonderful feature. See teh following example:
while True:
... try:
... x = int(raw_input("Please enter a number: "))
... break
... except ValueError:
... print "Oops! That was no valid number. Try again..."
Note: Code taken from python APIs.

twitter trends api UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: unexpected code byte

I am trying to follow the sample code of the book "Mining the social web", 1-3.
I know its old so I follow the new sample from the web page enter link description here
BUT, SOMETIMES, I will suffer a Error info when I implement the code:
[ trend.decode('utf-8') for trend in world_trends()[0]['trends'] ]
And the error info is like this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.6-universal/egg/twitter/api.py", line 167, in __call__
File "build/bdist.macosx-10.6-universal/egg/twitter/api.py", line 173, in _handle_response
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: unexpected code byte
It doesnt always happen, but I think no programmer likes such a "random" case.
So could anyone help me on this issue? Whats the problem and how I can solve this?
Great thanks~
byte 0x8b in position 1 usually signals that the data stream is gzipped. For similar problems, see here and here.
To unzip the data stream:
buf = StringIO.StringIO(<response object>.content)
gzip_f = gzip.GzipFile(fileobj=buf)
content = gzip_f.read()
By default decode() will throw an error if it encounters a byte that it doesn't know how to decode.
You can use trend.decode('utf-8', 'replace') or trend.decode('utf-8', 'ignore') to not throw an error and silently ignore it.
Documentation on decode() here.

Resources