Web platform for sharing free data for ML and research

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

Add graphical query option

roundabout,
created on Monday, 9 September 2024, 09:59:14 (1725875954), received on Monday, 9 September 2024, 09:59:17 (1725875957)
Author identity: vlad <vlad.muntoiu@gmail.com>

c97e3258558c1db7bb28a68400aaa83064daae7e

app.py

@@ -722,15 +722,7 @@ def copy_picture(id):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                return flask.redirect("/picture/" + str(new_resource.id))
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @app.route("/query-pictures", methods=["POST"])      # sadly GET can't have a body
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def query_pictures():
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            offset = int(flask.request.args.get("offset", 0))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            limit = int(flask.request.args.get("limit", 16))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            ordering = flask.request.args.get("ordering", "date-desc")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            yaml_parser = yaml.YAML()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query_data = yaml_parser.load(flask.request.data) or {}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def get_picture_query(query_data):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                query = db.session.query(PictureResource)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                requirement_conditions = {
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -770,6 +762,19 @@ def query_pictures():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                if not query_data.get("include_obsolete", False):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    query = query.filter(PictureResource.replaced_by_id.is_(None))
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return query
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @app.route("/query-pictures", methods=["POST"])      # sadly GET can't have a body
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def query_pictures():
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            offset = int(flask.request.args.get("offset", 0))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            limit = int(flask.request.args.get("limit", 16))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            ordering = flask.request.args.get("ordering", "date-desc")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            yaml_parser = yaml.YAML()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query_data = yaml_parser.load(flask.request.data) or {}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query = get_picture_query(query_data)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                match ordering:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    case "date-desc":
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        query = query.order_by(PictureResource.timestamp.desc())
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -830,6 +835,28 @@ def query_pictures():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                return response
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @app.route("/graphical-query-pictures")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def graphical_query_pictures():
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.render_template("graphical-query-pictures.html")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @app.route("/graphical-query-pictures-results")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def graphical_query_pictures_results():
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query_yaml = flask.request.args.get("query", "")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            yaml_parser = yaml.YAML()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query_data = yaml_parser.load(query_yaml) or {}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            query = get_picture_query(query_data)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            page = int(flask.request.args.get("page", 1))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            per_page = int(flask.request.args.get("per_page", 16))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            resources = query.paginate(page=page, per_page=per_page)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.render_template("graphical-query-pictures-results.html", resources=resources, query=query_yaml,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                          page_number=page, page_length=per_page, num_pages=resources.pages,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                          prev_page=resources.prev_num, next_page=resources.next_num)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            @app.route("/raw/picture/<int:id>")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            def raw_picture(id):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                resource = db.session.get(PictureResource, id)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/graphical-query-pictures-results.html

@@ -0,0 +1,48 @@

                                
                                
                                
                            
                                
                                    
                                        
                                        {% extends "default.html" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block title %}Picture query results | gigadata{% endblock %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block content %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            <x-frame style="--width: 768px">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                <h1>Picture query results</h1>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                <ul class="thumbnail-list">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    {% for resource in resources %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <li>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            <a href="/picture/{{ resource.id }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                <div class="annotation-zone">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    <img src="/raw/picture/{{ resource.id }}" alt="{{ resource.title }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    {% for region in resource.regions %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% if region.json.type == "bbox" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            <svg class="shape-container" viewBox="0 0 {{ resource.width }} {{ resource.height }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <rect x="{{ region.json.shape.x * resource.width }}"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                      y="{{ region.json.shape.y * resource.height }}"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                      width="{{ region.json.shape.w * resource.width }}"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                      height="{{ region.json.shape.h * resource.height }}"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                      fill="none" class="shape-bbox shape"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                ></rect>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            </svg>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% elif region.json.type == "polygon" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            <svg class="shape-container" viewBox="0 0 {{ resource.width }} {{ resource.height }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <polygon points="{% for point in region.json.shape %}{{ point.x * resource.width }},{{ point.y * resource.height }} {% endfor %}" fill="none" class="shape-polygon shape"></polygon>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            </svg>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% elif region.json.type == "polyline" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            <svg class="shape-container" viewBox="0 0 {{ resource.width }} {{ resource.height }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <polyline points="{% for point in region.json.shape %}{{ point.x * resource.width }},{{ point.y * resource.height }} {% endfor %}" fill="none" class="shape-polyline shape"></polyline>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            </svg>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% elif region.json.type == "point" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            <svg class="shape-container" viewBox="0 0 {{ resource.width }} {{ resource.height }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <circle cx="{{ region.json.shape.x * resource.width }}" cy="{{ region.json.shape.y * resource.height }}" r="0" fill="none" class="shape-point shape"></circle>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            </svg>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% endif %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    {% endfor %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                </div>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                <div class="list-detail">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    {{ resource.title }}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                </div>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            </a>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        </li>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    {% endfor %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                </ul>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                {% include "pagination.html" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            </x-frame>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% endblock %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/graphical-query-pictures.html

@@ -0,0 +1,16 @@

                                
                                
                                
                            
                                
                                    
                                        
                                        {% extends "default.html" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block title %}Query pictures | gigadata{% endblock %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block content %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            <x-frame style="--width: 768px">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                <h1>Query pictures</h1>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                <form method="GET" action="/graphical-query-pictures-results" class="vbox">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    <label>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <span class="required-asterisk">Query YAML</span>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <textarea name="query" required rows="16"></textarea>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    </label>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    <button type="submit">Search</button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                </form>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            </x-frame>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% endblock %}