瀏覽代碼

feat: 优化网页内容

SongZihuan 3 年之前
父節點
當前提交
f0143cad79

+ 32 - 10
app/data/views.py

@@ -52,8 +52,7 @@ def count_by_days():
     return Markup(bar.render_embed())
     return Markup(bar.render_embed())
 
 
 
 
-@data.route('/pyecharts/count_by_date/<int:days>')
-def count_by_date(days):
+def count_by_date__(days):
     if days != 7 and days != 30:
     if days != 7 and days != 30:
         abort(404)
         abort(404)
 
 
@@ -89,24 +88,47 @@ def count_by_date(days):
         y_data = res[i][::-1]  # 反转数据
         y_data = res[i][::-1]  # 反转数据
         line.add_yaxis(series_name=i, y_axis=y_data, color=random_color())
         line.add_yaxis(series_name=i, y_axis=y_data, color=random_color())
     line.add_yaxis(series_name="合计", y_axis=count_data[::-1], color=random_color())
     line.add_yaxis(series_name="合计", y_axis=count_data[::-1], color=random_color())
+    return line
 
 
-    return Markup(line.render_embed())
+
+@data.route('/pyecharts/count_by_date/<int:days>')
+def count_by_date(days):
+    if days == 307:
+        line7 = count_by_date__(7)
+        line30 = count_by_date__(30)
+        chart = pyecharts.charts.Tab("时间统计")
+        chart.add(line7, "7日统计")
+        chart.add(line30, "30日统计")
+    else:
+        chart = count_by_date__(days)
+    return Markup(chart.render_embed())
 
 
 
 
 @data.route('/pyecharts/count_passing_rate')
 @data.route('/pyecharts/count_passing_rate')
 def count_passing_rate():
 def count_passing_rate():
-    rate = views.website.count_passing_rate()
-    if rate is None:
+    rate_list = views.website.count_passing_rate()
+    if rate_list is None:
         abort(500)
         abort(500)
 
 
-    pie = pyecharts.charts.Pie(init_opts=init_opts)
+    page = pyecharts.charts.Tab("通过率")
+    xaxis_opts = pyecharts.options.AxisOpts(type_="category")
 
 
-    (pie.set_global_opts(xaxis_opts=pyecharts.options.AxisOpts(type_="category"),
-                         title_opts=pyecharts.options.TitleOpts(title="通过率")))
+    rate_global = 0
+    for i in rate_list:
+        name = GarbageType.GarbageTypeStrList_ch[int(i[0].decode("utf-8"))]
+        pie = pyecharts.charts.Pie(init_opts=init_opts)
+        pie.set_global_opts(xaxis_opts=xaxis_opts, title_opts=pyecharts.options.TitleOpts(title=f"{name}-通过率"))
+        pie.add(series_name=name, data_pair=[("通过", i[1]), ("不通过", 1 - i[1])], color=random_color())
+        page.add(pie, f"{name}-通过率")
+        rate_global += i[1]
 
 
-    pie.add(series_name="合计", data_pair=[("通过", rate), ("不通过", 1 - rate)], color=random_color())
+    rate_global = rate_global / 4
+    pie = pyecharts.charts.Pie(init_opts=init_opts)
+    pie.set_global_opts(xaxis_opts=xaxis_opts, title_opts=pyecharts.options.TitleOpts(title="平均-通过率"))
+    pie.add(series_name="平均", data_pair=[("通过", rate_global), ("不通过", 1 - rate_global)], color=random_color())
+    page.add(pie, "平均-通过率")
 
 
-    return Markup(pie.render_embed())
+    return Markup(page.render_embed())
 
 
 
 
 def creat_data_website(app_: Flask):
 def creat_data_website(app_: Flask):

+ 14 - 1
app/static/styles/base.css

@@ -31,7 +31,6 @@ nav.nav-top {
     #start-p {
     #start-p {
         height: 0;
         height: 0;
     }
     }
-
 }
 }
 
 
 @media not all and (max-width: 1200px) {
 @media not all and (max-width: 1200px) {
@@ -73,6 +72,20 @@ li.nav-top-item {
     display: inline-block;
     display: inline-block;
 }
 }
 
 
+@media all and (max-width: 1200px) {
+    /*覆盖上面的设定*/
+    /* 小屏幕不显示 */
+    .nav-top-phone-display {
+        display: none;
+    }
+}
+
+@media all and (min-width: 1200px) {
+    .nav-top-phone-display {
+        display: inline-block;
+    }
+}
+
 a.nav-top-item {
 a.nav-top-item {
     display: inline-block;
     display: inline-block;
     padding-left: 20px;
     padding-left: 20px;

+ 10 - 2
app/static/styles/data/data.css

@@ -1,10 +1,18 @@
-.pyecharts-frame {
+.pyecharts-frame-l, .pyecharts-frame {
     width: 1100px;
     width: 1100px;
-    height: 550px;
     border: 0;
     border: 0;
     margin: 10px auto;
     margin: 10px auto;
 }
 }
 
 
+.pyecharts-frame {
+    height: 550px;
+}
+
+.pyecharts-frame-l {
+    height: 600px;
+}
+
+
 .title {
 .title {
     margin-top: 20px;
     margin-top: 20px;
     font-size: 23px;
     font-size: 23px;

+ 1 - 1
app/static/styles/store/store.css

@@ -29,7 +29,7 @@
 
 
 #info-score {
 #info-score {
     margin: 0 10px;
     margin: 0 10px;
-    float: right;
+    text-align: center;
 }
 }
 
 
 #store-item {
 #store-item {

+ 3 - 2
app/templates/base.html

@@ -52,8 +52,9 @@
             <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('news.index', page=1) }}">
             <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('news.index', page=1) }}">
                 博客 </a></li>
                 博客 </a></li>
 
 
-            <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('data.index', page=1) }}">
-                统计 </a></li>
+            <li class="nav-top-phone-display">
+                <a class="nav-top-item" href="{{ url_for('data.index', page=1) }}">
+                    统计 </a></li>
 
 
             {% if current_user.is_authenticated %}
             {% if current_user.is_authenticated %}
                 <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('auth.about') }}">
                 <li class="nav-top-item"><a class="nav-top-item" href="{{ url_for('auth.about') }}">

+ 2 - 3
app/templates/data/data.html

@@ -16,11 +16,10 @@
     <br>
     <br>
     <h2 class="title"> 按日期统计垃圾量 </h2>
     <h2 class="title"> 按日期统计垃圾量 </h2>
     <p class="info"> 将数据库中的所有数据按日期进行分类,然后获取统计值。 </p>
     <p class="info"> 将数据库中的所有数据按日期进行分类,然后获取统计值。 </p>
-    <iframe class="pyecharts-frame" src="{{ url_for("data.count_by_date", days=7) }}"></iframe>
-    <iframe class="pyecharts-frame" src="{{ url_for("data.count_by_date", days=30) }}"></iframe>
+    <iframe class="pyecharts-frame-l" src="{{ url_for("data.count_by_date", days=307) }}"></iframe>
 
 
     <br>
     <br>
     <h2 class="title"> 垃圾分类通过率 </h2>
     <h2 class="title"> 垃圾分类通过率 </h2>
     <p class="info"> 计算用户投放垃圾反馈结果为投放正确的概率。 </p>
     <p class="info"> 计算用户投放垃圾反馈结果为投放正确的概率。 </p>
-    <iframe class="pyecharts-frame" src="{{ url_for("data.count_passing_rate") }}"></iframe>
+    <iframe class="pyecharts-frame-l" src="{{ url_for("data.count_passing_rate") }}"></iframe>
 {% endblock %}
 {% endblock %}

+ 16 - 0
app/templates/hello/index.html

@@ -13,6 +13,7 @@
     <h2 class="hello"> 本站介绍 </h2>
     <h2 class="hello"> 本站介绍 </h2>
     <p class="hello"> 欢迎访问 {{ loc }} 垃圾站的在线网站,这里将展示 {{ loc }} 垃圾站的信息。 </p>
     <p class="hello"> 欢迎访问 {{ loc }} 垃圾站的在线网站,这里将展示 {{ loc }} 垃圾站的信息。 </p>
     <p class="hello"> 高分榜和警示榜将展示在本垃圾站投放垃圾的用户的信用和积分排行。 </p>
     <p class="hello"> 高分榜和警示榜将展示在本垃圾站投放垃圾的用户的信用和积分排行。 </p>
+    <p class="hello"> 统计(移动端无法查看)将展示本站的公开信息。 </p>
     <p class="hello"> 祝您浏览愉快。 </p>
     <p class="hello"> 祝您浏览愉快。 </p>
 
 
     <h2 class="hello"> 高分榜 </h2>
     <h2 class="hello"> 高分榜 </h2>
@@ -25,6 +26,21 @@
         警示榜将用户倒序排行,显示低分用户。
         警示榜将用户倒序排行,显示低分用户。
     </p>
     </p>
 
 
+    <h2 class="hello"> 积分商城 </h2>
+    <p class="hello">
+        可以使用积分在该商城挑选心仪的商品进行兑换。
+    </p>
+
+    <h2 class="hello"> 博客 </h2>
+    <p class="hello">
+        可以发表你的意见、文章。
+    </p>
+
+    <h2 class="hello"> 统计 </h2>
+    <p class="hello">
+        垃圾站公开的统计数据。
+    </p>
+
     <h2 class="hello"> Q&A </h2>
     <h2 class="hello"> Q&A </h2>
     <h3 class="hello"> 什么是HGSSystem垃圾站系统?</h3>
     <h3 class="hello"> 什么是HGSSystem垃圾站系统?</h3>
     <p class="hello">
     <p class="hello">

+ 5 - 4
app/web.py

@@ -167,16 +167,17 @@ class DataWebsite(WebsiteBase):
         return cur.fetchall()
         return cur.fetchall()
 
 
     def count_passing_rate(self):
     def count_passing_rate(self):
-        cur = self._db.search(columns=[f"get_avg(count(GarbageID), "
+        cur = self._db.search(columns=["GarbageType",
+                                       f"get_avg(count(GarbageID), "
                                        f"(SELECT count(g.GarbageID) "
                                        f"(SELECT count(g.GarbageID) "
                                        f"FROM garbage AS g WHERE g.CheckResult is not null)) AS count"],
                                        f"FROM garbage AS g WHERE g.CheckResult is not null)) AS count"],
                               table="garbage",
                               table="garbage",
                               where=["CheckResult is not null", "CheckResult=1"],
                               where=["CheckResult is not null", "CheckResult=1"],
-                              order_by=[("count", "DESC")])
+                              group_by=["GarbageType"],
+                              order_by=[("GarbageType", "ASC")])
         if cur is None or cur.rowcount == 0:
         if cur is None or cur.rowcount == 0:
             return None
             return None
-        assert cur.rowcount == 1
-        return cur.fetchone()[0]
+        return cur.fetchall()
 
 
 
 
 class Website(AuthWebsite, StoreWebsite, RankWebsite, NewsWebsite, DataWebsite, WebsiteBase):
 class Website(AuthWebsite, StoreWebsite, RankWebsite, NewsWebsite, DataWebsite, WebsiteBase):