当前位置:网站首页>App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
2022-04-23 01:50:00 【Progressive vegetable pig】
List of articles
Author's brief introduction : Hello everyone , I'm an up and comer pig . Inner Mongolia University of science and technology , Sophomore Planning Department . Technology is good, but don't give up , Try to do the whole stack . Love development , Development software , Develop web site , Develop all kinds of things .️
️ Personal home page : The blog of self-motivated vegetable pig
Series column : This article is written in 《APP Development from 0 To 1》 special column ️ If there is something wrong with the knowledge of the article , Please correct me. ! Study with you and make progress together
If you think the blogger's article is good , Three companies, please + Pay attention to and support bloggers
One , Preface
Next chapter . Mentioned in the previous article :
Today, there is another small demand : as follows : The ranking list can view the class ranking .
Problems to be solved :
1, Class attributes need to be added when registering .
2, The database needs a small change .
3, For the sake of friendliness , I added a segment display in the personal championship . Very friendly .
4, Add class ranking to the ranking list .
And I wrote the first three requirements , Write down the fourth requirement today .
Two , Back end —— Class ranking
First , Define a sum Variable , Inside mongo All data of table .
list_clss=[]
sum = db.mongo.find()
Define an empty list_clss list .
Purpose : Let's traverse the class value .
for i in sum:
sum_fries.append(i)
if(i['class'] not in list_clss):
list_clss.append(i['class'])
The above code block is explained as follows :
Let's loop through sum.
then sum_fries Is another storage sum Table content ( It's equivalent to making a copy of ).
Add a traversal storage condition . If , Now traverse to the value . stay list_clss If it is not in the list, add it , If . Some words , No additional .
Realization function :
De duplication function , Extract the registered user class now , Convenient follow-up operation .
list_clss_sum=[]
list_clss_people=[]
The above code block is explained as follows : Define two empty lists .
One is to put the total class points , The other is to put the number of classes , The listed method stores .

The above code block is explained as follows : Get list length , loop , Accumulate the current points of the people in the target class , Store in the corresponding sum In the list .
The number of people is the same , Every time you find a target , Self increase one .
str(list_clss[j])==str(ii[‘class’]), This is the screening criteria .
for jj in range(0,len(list_clss)):
The following is all right mongodb Data operation problems , as follows :

Get our dictionary set ready .
if(find==None):
db.classdb.insert_one(classdb)
if(find!=None and find_again==None):
db.classdb.update_one(
class_find,
{
'$set':class_again
}
)
The above code block is explained as follows :
Situation 1 : If you don't find the current content in the class data , Do the add operation , The code above find==none.
Situation two : If the goal is already in the class database , But it's not exactly the same , We need to perform the update mongodb Operation of database .
after_find=db.classdb.find({
}).sort([("average", -1)])
Last , Code above , We use mongodb Sorting function of , Has been evenly divided into goals , Sort in descending order .
append=[]
for i in after_find:
append.append(i)
print(append)
Then write a traversal , Put the sorted database target value , Add one by one to append in . Then pass it to the front end , Realize the functional requirements of class ranking .
3、 ... and , Results display

Last .MUI Zhenwen !
版权声明
本文为[Progressive vegetable pig]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220911390799.html
边栏推荐
- K zeros after leetcode factorial function
- When should I write unit tests? What is TDD?
- 2022 crane driver (limited to bridge crane) examination question bank and online simulation examination
- Makefile文件是什么?
- 教程】如何用GCC“零汇编”白嫖MDK
- 紫光国微财报一枝独秀 2021年净利润三位数增长靠什么
- What should I pay attention to when using proxy IP?
- JSP basic knowledge summary
- 2022.4.10-----leetcode. eight hundred and four
- 动态代理ip的测试步骤有哪些?
猜你喜欢

一些使用代理IP的小技巧。

如何选择一台好的拨号服务器?

什么时候应该编写单元测试?什么是TDD?

Technology cloud report: cloud computing has entered the "second half". Where is the way out for domestic cloud?

J-Link RTT使用

Shardingsphere sub database and sub table

What are the test steps of dynamic proxy IP?

W801/W800-wifi-socket开发(二)-UDP蓝牙控制wifi连接

Error in face detection and signature of Tencent cloud interface

2022 crane driver (limited to bridge crane) examination question bank and online simulation examination
随机推荐
When should I write unit tests? What is TDD?
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
如何“优雅”的测量系统性能
角色個人屬性英文縮寫
有哪些业务会用到物理服务器?
What businesses use physical servers?
Some tips for using proxy IP.
CDR2022首发全新版本性能介绍
客户端项目管理经常面临的挑战
W801/W800-wifi-socket开发(一)-UDP
LSF的常用使用命令总结
English abbreviation of role personal attribute
npm——配置淘宝镜像
mb_ substr()、mb_ Strpos() function (story)
Summary of LSF usage
The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?
什么是代理IP池,如何构建?
How to initialize "naming and surname" in C language
[tutorial] how to use GCC "zero assembly" for white whoring MDK
keil mdk中文乱码,两种解决方法,字体不再难看