Smart canteen data analysis system

Smart Canteen Data Analysis System | Big Data Analysis | Data Visualization

Demo

  • Username: admin
  • Password: 123456

Table of Contents

Background

As the enrollment scale of colleges and universities continues to expand, the traditional canteen production methods and business concepts have become bottlenecks in the development of colleges and universities.

Due to the diverse and increasingly complex dietary needs of college students, traditional canteens have gradually lost their competitiveness. Due to the lack of student satisfaction feedback, or the long time to obtain feedback and the single channel, the canteen operation and management is lagging behind, and problems cannot be discovered and improved in time. In terms of canteen finance, a large amount of form data is needed to reflect canteen sales, which is cumbersome and error-prone.

Features

  • The backend of the smart canteen data analysis system can clear and compile statistics on daily canteen dish sales data, and return turnover, order volume, foot traffic, and average dish ratings on a daily basis.
  • The smart canteen data analysis system calculates what nutrients are contained in the food consumed at each meal. Both students and the canteen can clearly see the nutrients consumed today through the canteen management system platform.
  • After the user has finished their meal, they can comment on the dishes in the canteen through the rating function. The backend of the smart canteen data analysis system will collect these data and then send these data to the canteen manager.

Database

Insert image description here

The amount of data:

  • 100 items in food table
  • menu table 106370 items
  • orderform table 35496 items
  • 500 entries in user table

data processing

Insert image description here

Insert image description here

ARIMA time series forecast sales

Insert image description here

Here, we use the first 27 days of restaurant sales as source data to predict the restaurant's sales in the last 3 days, that is, set the number of prediction steps to 3. The final result chart is as shown below.

The gray line is the 27 data used for training, the black line is the prediction of future values, and the red line is the upper and lower limits of the 95% confidence interval. In other words, there is a 95% probability that the future true value will fall within this range. In addition to this, it can be seen that the results of long-term forecasting using the ARIMA method are trendy.

This completes the restaurant sales forecast based on ARIMA time series. The forecasted restaurant sales data for the last three days are 14733, 15457 and 16058 respectively. Observation shows that the obtained results are not much different from the source data and are in line with the price trend.

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

front-end framework

Insert image description here

  • The front-end adopts Bootstrap responsive layout design, which is compatible with devices of different resolutions and provides users with a better visual experience.
  • ApexCharts is used for data visualization. Compared with Echarts, ApexCharts is more lightweight, has simple and beautiful icons, and is highly customizable. However, ApexCharts documentation is incomplete, which makes development difficult.
  • Requesting remote data uses jQuery's AJAX implementation. When entering the website, all data is requested asynchronously, and then charts are rendered to achieve data visualization.
  • After basically realizing the front-end static web page style, create a JSP dynamic web page to implement services such as login and data request.
  • JSON parsing in JSP uses Alibaba's Fastjson to realize the conversion of json objects and JavaBean objects.
  • Use Maven to manage JAVA projects and use Git for project version control.

backend framework

Insert image description here

The backend uses the Spring+SpringMVC+Mybatis+Redis framework.

  • Use SSM framework to implement eight modules and a total of seventeen interfaces
  • Use AOP cross-cutting and weaving methods to integrate Redis for some parameterless interfaces with slow back-end processing, and serialize and store the Response.
  • Use c3p0 connection pool to improve reuse and reduce database pressure
  • Use AOP cross-cutting and weaving methods to integrate Redis for some parameterless interfaces with slow back-end processing, and serialize and store the Response.
  • Abandon traditional JDBC and use c3p0 connection pool to reduce database pressure
  • In the login business, the password is encrypted by MD5 twice on the front and back ends, and single sign-on is implemented by writing Cookie and Redis.

Version iteration:

7.09 Project construction and server environment construction realize the interface of business 1: orders are gathered according to time

7.10 Found the interface bug of business 1, provided the avoidance method, and implemented the interface of business 5: the difference in consumption levels between men and women

7.11 Optimize the interface of business 1: return data in ascending order by time period, optimize the interface of business 5: change the Chinese parameter name to English, and implement the interface of business 8: return turnover, order volume, traffic flow, and average rating by day

7.12 Added parameter judgment to some interfaces, and implemented the interface of business 2: return the list of the most popular, unpopular, highest-selling, and lowest-selling dishes, and searched for a bug in the packaged version for a day...

7.13 Implemented the interface of business 4: human flow in three time periods every day

7.14 In response to the front-end requirements, the business 8 interface is integrated. The framework integrates redis, implements the administrator login interface and adds related tool classes, adds cross-domain request configuration, and implements the business 11 interface: paging query.

7.15 Added more query data items for business 4, integrated the total transaction amount interface, deleted the original total transaction amount interface, added the average nutritional value of three meals interface, and fixed the bug that the business 8 interface would explode when the parameter passed was 1.

7.16 Integrated new redis for some no-parameter interfaces, modified some data interfaces to improve the login interface

7.18 Implement Cookie verification interface

Business needs one

1.1 Requirements design

Smart canteen system login request business

1.2 Core code

public class AdminLoginServiceImpl implements AdminLoginService{
    
    


    @Resource
    private RedisUtil redisUtil;
    private AdminLoginMapper adminLoginMapper;

    public void setAdminLoginMapper(AdminLoginMapper adminLoginMapper) {
    
    
        this.adminLoginMapper = adminLoginMapper;
    }

    @Override
    public int login(String username, String password, HttpServletRequest request, HttpServletResponse response) {
    
    

        //根据用户名获取用户
        Admin admin = adminLoginMapper.getAdminByUsername(username);
        if(null == admin){
    
    
            //用户不存在
            return 0;
        }
        //密码校验
        if(!MD5util.formPassToDBPass(password,admin.getSalt()).equals(admin.getPassword())){
    
    
            //密码错误
            return 1;
        }
        //生成Cookie
        String ticket = UUIDUtil.uuid();
        //Session存入redis
        if(redisUtil.hasKey(username)){
    
    
            //单点登录需删除用户已有Session
            redisUtil.del((String) redisUtil.get(username));
            redisUtil.del(username);
        }
        redisUtil.set(ticket,username,2000);
        redisUtil.set(username,ticket,2000);
        //写入Cookie
        CookieUtil.setCookie(request,response,"ticket",ticket,-1);
        //登陆成功
        return 2;
    }

    @Override
    public int getUserByCookie(HttpServletRequest request, HttpServletResponse response) {
    
    
        String Cookie = CookieUtil.getCookieValue(request,"ticket");
        if(redisUtil.hasKey(Cookie)){
    
    
            //重置缓存失效时间
            redisUtil.expire(Cookie,2000);
            redisUtil.expire((String) redisUtil.get(Cookie),2000);
            //0表示已登录状态
            return 0;
        }
        //1表示未登录状态,前端需重定向登录页
        return 1;
    }
}

1.3 Effect display

Insert image description here

Business needs two

2.1 Requirements design

Displays the total number of orders, average order rating, total customer flow, and total turnover for the day

2.2 Core code

-- 当天订单的平均评分
SELECT avg(X.result1) AS RESULT
FROM(SELECT menu_id,avg(mark) AS result1 FROM menu
WHERE menu_id IN
(SELECT menu_id FROM orderform WHERE DATE(TIME)='2022-06-29')
GROUP BY menu_id) X;
 
-- 当天的总订单总数
SELECT COUNT(*) AS num
FROM orderform
WHERE DATE(TIME)='2022-06-29';
 
-- 当天的总访客数量
SELECT COUNT(DISTINCT user_id) AS num
FROM orderform
WHERE DATE(TIME)='2022-06-29';
 
-- 当天的总交易额
SELECT SUM(total_money)
FROM orderform
WHERE DATE(TIME)='2022-06-29';

2.3 Effect display

Insert image description here

Business requirement three

3.1 Requirements design

Displays the total daily turnover, total number of visitors, average order rating, and total order quantity within a month. Normalize the data and show the changing trend of the data.

3.2 Core code

-- 30天每日订单平均评分
SELECT DATE(TIME) AS TIME,avg(X.avg_menu) AS avg_mark
FROM orderform,
(SELECT menu_id,avg(mark) AS avg_menu
FROM menu
GROUP BY menu_id) AS X
WHERE X.menu_id=orderform.menu_id
GROUP BY DATE(TIME)
ORDER BY DATE(TIME) LIMIT 30;

-- 30天每日总交易额
SELECT DATE(TIME)AS TIME, SUM(total_money)
FROM orderform
GROUP BY DATE(TIME) ORDER BY TIME LIMIT 30;

-- 30天每日订单数量
SELECT DATE(TIME)AS TIME, COUNT(*) AS order_num
FROM orderform
GROUP BY DATE(TIME) ORDER BY TIME LIMIT 30;

-- 30天每日总访客量
SELECT DATE(TIME)AS TIME, COUNT(DISTINCT user_id) AS order_num
FROM orderform
GROUP BY DATE(TIME) ORDER BY TIME LIMIT 30;

3.3 Effect display

Insert image description here

Business requirement four

4.1 Requirements design

Predict the next day's total turnover, total number of visitors, average order rating, and total order quantity

4.2 Core code

clear all;
clc;
filename='D:\Desktop\分布式任务\ARIMA时间序列预测结果图\transaction_data.csv';
Y=csvread(filename,1,1,[1,1,27,1]);
Y=ceil(Y);
Y=Y';
plot(Y)

%ACF和PACF图
figure
autocorr(Y)
figure
parcorr(Y)

%平滑性检验,yd1_h_adf =1,yd1_h_kpss =0,通过检验
y_h_adf = adftest(Y);
y_h_kpss = kpsstest(Y);

% 一阶差分,结果平稳。如果依旧不平稳的话,再次求差分,直至通过检验
Yd1 = diff(Y);
yd1_h_adf = adftest(Yd1);
yd1_h_kpss = kpsstest(Yd1);

%Yd2转换成列向量
Yd1=Yd1';
Y=Y';

LOGL = zeros(4,4); % Initialize
PQ = zeros(4,4);
for p = 1:4
    for q = 1:4
        Mdl = arima(p,1,q);
        [~,~,logL] = estimate(Mdl,Yd1,'Display','off');
        LOGL(p,q) = logL;
        PQ(p,q) = p + q;
     end
end

%reshape 重构数组
LOGL = reshape(LOGL,16,1);
PQ = reshape(PQ,16,1);
[~,bic] = aicbic(LOGL,PQ+1,100);
a=reshape(bic,4,4);

% 找最佳lags值 x=2,y=1,即对应ARMA(2,1)模型
a_max=max(a(:));
[x,y]=find(a==min(a(:)));


Mdl = arima(x, 1, y);  %第二个变量值为1,即一阶差分
EstMdl = estimate(Mdl,Y);
[res,~,logL] = infer(EstMdl,Y);   %res即残差

stdr = res/sqrt(EstMdl.Variance);
figure('Name','残差检验')
subplot(2,3,1)
plot(stdr)
title('Standardized Residuals')
subplot(2,3,2)
histogram(stdr,10)
title('Standardized Residuals')
subplot(2,3,3)
autocorr(stdr)
subplot(2,3,4)
parcorr(stdr)
subplot(2,3,5)
qqplot(stdr)
%上图为残差检验的结果图。
% Standardized Residuals是查看残差是否接近正态分布,理想的残差要接近正态分布;
% ACF和PACF检验残差的自相关和偏自相关,理想的结果应该在图中不存在超出蓝线的点;
% 最后一张QQ图是检验残差是否接近正太分布的,理想的结果中蓝点应该靠近红线。

% Durbin-Watson 统计是计量经济学分析中最常用的自相关度量
diffRes0 = diff(res);  
SSE0 = res'*res;
DW0 = (diffRes0'*diffRes0)/SSE0; % Durbin-Watson statistic,
% 该值接近2,则可以认为序列不存在一阶相关性。

%% 5.预测
step = 3; % 预测步数为 3
[forData,YMSE] = forecast(EstMdl,step,'Y0',Y);   
lower = forData - 1.96*sqrt(YMSE); %95置信区间下限
upper = forData + 1.96*sqrt(YMSE); %95置信区间上限

plot(forData)
disp(forData)

figure()
plot(Y,'Color',[.7,.7,.7]);
hold on
h1 = plot(length(Y):length(Y)+step,[Y(end);lower],'r:','LineWidth',2);
plot(length(Y):length(Y)+step,[Y(end);upper],'r:','LineWidth',2)
h2 = plot(length(Y):length(Y)+step,[Y(end);forData],'k','LineWidth',2);
legend([h1 h2],'95% 置信区间','预测值',...
	     'Location','NorthWest')
title('Forecast')
hold off

4.3 Effect display

Insert image description here

Business requirement five

5.1 Requirements design

Average intake of various nutrients (including calories, protein, fat, carbohydrates, vitamins) in three meals within a month

5.2 Core code

SELECT (CASE 
WHEN HOUR(TIME) BETWEEN 6 AND 9 THEN 'morning' 
WHEN HOUR(TIME) BETWEEN 10 AND 13 THEN 'afternoon' 
WHEN HOUR(TIME) BETWEEN 16 AND 20 THEN 'evening' END) AS timeperiod,
SUM(calorie)/COUNT( DISTINCT order_id) AS avg_calorie,
SUM(carbohydrate)/COUNT( DISTINCT order_id) AS avg_arbohydrate,
SUM(fat)/COUNT( DISTINCT order_id) AS avg_fat,SUM(protein)/COUNT( DISTINCT order_id) AS avg_protein,
SUM(vitamin)/COUNT( DISTINCT order_id) AS avg_vitamin
FROM menu,orderform,food
WHERE menu.menu_id=orderform.menu_id  AND food.food_id= menu.food_id AND MONTH(TIME)='6'

5.3 Effect display

Insert image description here

Business requirement six

6.1 Requirements design

The 10 most popular dishes and the 10 worst-rated dishes

6.2 Core code

--评价最差的n道菜(最不受欢迎)
SELECT food.food_id,food.name,avg(mark) AS avg_markFROM menu,foodWHERE menu.food_id=food.food_idGROUP BY food_id ORDER BY avg_mark ASC LIMIT 10;

--销量最高的10道菜(最受欢迎)
 SELECT food.food_id,food.name,COUNT(*) AS order_numFROM menu,foodWHERE menu.food_id=food.food_idGROUP BY food_id ORDER BY order_num DESC LIMIT 10;

6.3 Effect display

Insert image description here

Business requirement seven

7.1 Requirements design

Display the latest 60 order data (displayed in pages), and can support conditional query

7.2 Core code

Database query code

SELECT order_id,user_id, X.content,TIME,total_money FROM
(SELECT menu_id,group_concat(food.name) AS content
FROM menu,food
WHERE menu.food_id = food.food_id
GROUP BY menu.menu_id) AS X,orderform
WHERE X.menu_id=orderform.menu_id
ORDER BY TIME DESC LIMIT 60 ;

java code

package com.jiang.service;

import com.jiang.mapper.OrderMapper;
import com.jiang.pojo.Order;

import java.util.List;

public class OrderListServiceImpl implements OrderListService{
    
    

    private OrderMapper orderMapper;

    public void setOrderMapper(OrderMapper orderMapper) {
    
    
        this.orderMapper = orderMapper;
    }

    @Override
    public List<Order> getList() {
    
    
        return orderMapper.getOrderListByPage();
    }
}

7.3 Effect display

Insert image description here

Overall effect display

Insert image description here

Conclusion

Meet expected project results

  • It implements a series of functions such as dish rating, healthy eating, order management, and backend management.
  • Login function implemented.
  • Completed the ARIMA time series forecast sales algorithm for forecasting sales.

Where the project needs improvement

  • Realize data analysis of multiple canteens.
  • Achieve the proportion of food nutrition in three meals meeting the standard.
  • Real-time addition, deletion, modification and query of data can be realized on the web page.

Contributor

Insert image description here

Guess you like

Origin blog.csdn.net/IYXUAN/article/details/125941695