-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use autotask to generate map in background
- Loading branch information
Showing
6 changed files
with
70 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
created 12.06.2018 by Jens Diemer <opensource@jensdiemer.de> | ||
:copyleft: 2018 by the django-for-runners team, see AUTHORS for more details. | ||
:license: GNU GPL v3 or above, see LICENSE for more details. | ||
""" | ||
import io | ||
import logging | ||
|
||
from autotask.tasks import delayed_task | ||
from for_runners.gpx_tools.garmin2gpxpy import garmin2gpxpy | ||
from for_runners.gpx_tools.gpxpy2map import generate_map | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@delayed_task() | ||
def generate_gpx_map_task(object_id): | ||
""" | ||
Delayed task to generate the map from GPX track | ||
""" | ||
log.debug("Generate GPX Map for ID: %r", object_id) | ||
|
||
from for_runners.models import GpxModel # import here, because of import-loop | ||
gpx_instance = GpxModel.objects.get(pk=object_id) | ||
log.info("Generate GPX Map for: %s" % gpx_instance) | ||
|
||
content = gpx_instance.gpx | ||
gpxpy_instance = garmin2gpxpy(content) | ||
|
||
image, plt = generate_map(gpxpy_instance) | ||
|
||
temp = io.BytesIO() | ||
plt.savefig(temp, bbox_inches="tight") | ||
|
||
# Save gpx map file to model instance: | ||
gpx_instance.map_image.save("gpx", temp) | ||
|
||
log.info("GPX data saved to %s, ok." % gpx_instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
:license: GNU GPL v3 or above, see LICENSE for more details. | ||
""" | ||
|
||
__version__ = '0.0.2' | ||
__version__ = '0.0.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters