Data_day_detail{startidx,4}(sendIdx,2) = Data_day_detail{startidx,4}(sendIdx,2) + Data_int(i,4); Data_day_detail{startidx,4}(receIdx,3) = Data_day_detail{startidx,4}(receIdx,3) + Data_int(i,4); routeIDX = sendIdx * 100 + receIdx; findResult = find(Data_route(:,1)==routeIDX); if isempty(findResult) tempdata = zeros(1,TotalDateNum+1); tempdata(1,1) = routeIDX; tempdata(1,startidx+1) = Data_int(i,4); Data_route = [Data_route;tempdata]; else Data_route(findResult(1,1),startidx+1) = Data_int(i,4); end什么意思
时间: 2023-06-06 09:07:30 浏览: 106
这段代码是一个MATLAB程序,主要是对数据进行处理和分析。具体来说,它首先从Data_day_detail这个数据数组中提取出发送者和接收者的索引,并将它们对应的日期信息存放在了Data_int这个数组中。然后,它根据发送者和接收者的索引计算出一个路由编号,并在Data_route这个数组中查找是否已经存在该路由编号。如果不存在,则会新增一个元素,如果存在,则更新对应元素的日期信息。最终将处理好的数据存放在Data_route中。
相关问题
Data_day_detail{startidx,3} = [Data_day_detail{startidx,3};Data_int(i,:)];什么意思
?这段代码是将 Data_int 中第 i 行的数据添加到 Data_day_detail 中第 startidx 行的第三列中。具体来说,这两个数据文件应该是一个二维矩阵,而这个代码实现的是在每个日期的详细数据中,将当前日期的数据添加到详细数据中去。
修改完整版的sql存储(积分兑换脚本),改写出可执行的hive脚本create procedure "rptdev"."sp_wjq_jf_value_dhfz_show"( in @data_date integer default cast("dateformat"("now"()-1,'yyyymmdd') as integer), in @is_run_flag1 integer default 1, in @is_run_flag2 integer default 10 ) on exception resume /****************************************************************** -- Purpose : 兑换积分分析报表 -- Auther: xxx -- Date : 20210923 *******************************************************************/ begin declare @stat_date varchar(8); --统计日期 declare @month_id integer; --统计月份 declare @month_first_date varchar(8); --统计月的第一天 declare @month_last_date varchar(8); --统计月的最后一天 declare @last_month_first_date varchar(8); --上月的第一天 declare @last_month_last_date varchar(8); --上月的最后一天 declare @last_month integer; --上月 declare @last_last_month integer; --上上月 declare @last_month_this_day varchar(8); --上月当天 declare @last_year_this_month integer; --上年当月 declare @this_year_first_month integer; --本年首月 declare @last_year_last_month integer; --上年尾月 set @stat_date = convert(varchar(8),@data_date); set @month_id = @data_date/100; set @month_first_date = "dateformat"(@data_date,'yyyymm01'); --统计月的第一天 set @month_last_date = "dateformat"("dateadd"("dd",-1,"dateformat"("dateadd"("mm",1,@data_date),'yyyymm01')),'yyyymmdd'); --统计月的最后一天 set @last_month_first_date = "dateformat"("dateadd"("mm",-1,@data_date),'yyyymm01'); --上月第一天 set @last_month_last_date = "dateformat"("dateadd"("dd",-1,"dateformat"("dateadd"("mm",1,@data_date),'yyyymm01')),'yyyymmdd'); set @last_month = cast("dateformat"("dateadd"("month",-1,@data_date),'yyyymm') as integer); --上月 set @last_last_month = cast("dateformat"("dateadd"("month",-2,@data_date),'yyyymm') as integer); --上上月 set @last_month_this_day = "dateformat"("dateadd"("mm",-1,convert(date,@data_date)),'yyyymmdd'); --上月当天 set @last_year_this_month = convert(integer,"dateformat"("dateadd"("yy",-1,@last_month_this_day),'yyyymm')); --上年当月
--将存储过程改写成Hive脚本
--设置变量
SET data_date = from_unixtime(unix_timestamp()-86400,'yyyyMMdd');
SET is_run_flag1 = 1;
SET is_run_flag2 = 10;
--获取日期相关变量
SET stat_date = CAST(data_date AS VARCHAR(8));
SET month_id = CAST(data_date/100 AS INT);
SET month_first_date = CONCAT(SUBSTR(data_date, 1, 6), '01');
SET month_last_date = DATE_FORMAT(DATE_ADD(month_first_date, INTERVAL 1 MONTH), 'yyyyMMdd') - 1;
SET last_month_first_date = DATE_FORMAT(DATE_ADD(month_first_date, INTERVAL -1 MONTH), 'yyyyMMdd');
SET last_month_last_date = DATE_FORMAT(DATE_ADD(month_first_date, INTERVAL -1 DAY), 'yyyyMMdd');
SET last_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), 'yyyyMM') AS INT);
SET last_last_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -2 MONTH), 'yyyyMM') AS INT);
SET last_month_this_day = DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), 'yyyyMMdd');
SET last_year_this_month = CAST(DATE_FORMAT(DATE_ADD(last_month_this_day, INTERVAL -1 YEAR), 'yyyyMM') AS INT);
SET this_year_first_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -MONTH(data_date) MONTH), 'yyyyMM') AS INT);
SET last_year_last_month = CAST(DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 YEAR), 'yyyyMM') AS INT);
--创建临时表
DROP TABLE IF EXISTS tmp_jf_value_dhfz_show;
CREATE TABLE tmp_jf_value_dhfz_show AS
SELECT
t1.cust_id,
t1.cust_name,
t2.channel_name,
t1.consume_value,
t1.exchange_value,
t1.this_month_value,
t1.last_month_value,
t1.last_last_month_value,
t1.last_year_this_month_value,
t1.this_year_first_month_value,
t1.last_year_last_month_value,
t1.month_id
FROM
(
--获取本月和上月的兑换积分数
SELECT
cust_id,
cust_name,
SUM(CASE WHEN consume_date >= month_first_date AND consume_date <= month_last_date THEN consume_value ELSE 0 END) AS consume_value,
SUM(CASE WHEN exchange_date >= month_first_date AND exchange_date <= month_last_date THEN exchange_value ELSE 0 END) AS exchange_value,
SUM(CASE WHEN consume_date >= last_month_first_date AND consume_date <= last_month_last_date THEN consume_value ELSE 0 END) AS last_month_value,
SUM(CASE WHEN exchange_date >= last_month_first_date AND exchange_date <= last_month_last_date THEN exchange_value ELSE 0 END) AS last_month_exchange_value,
SUM(CASE WHEN consume_date >= DATE_FORMAT(DATE_ADD(last_month_first_date, INTERVAL -1 MONTH), 'yyyyMMdd')
AND consume_date <= DATE_FORMAT(DATE_ADD(last_month_last_date, INTERVAL -1 MONTH), 'yyyyMMdd') THEN consume_value ELSE 0 END) AS last_last_month_value,
SUM(CASE WHEN consume_date >= DATE_FORMAT(DATE_ADD(last_month_this_day, INTERVAL -1 YEAR), 'yyyyMMdd')
AND consume_date <= DATE_FORMAT(DATE_ADD(last_month_this_day, INTERVAL -1 YEAR MONTH), 'yyyyMM') THEN consume_value ELSE 0 END) AS last_year_this_month_value,
SUM(CASE WHEN consume_date >= DATE_FORMAT(DATE_ADD(data_date, INTERVAL -MONTH(data_date) MONTH), 'yyyyMMdd')
AND consume_date <= month_last_date THEN consume_value ELSE 0 END) AS this_month_value,
SUM(CASE WHEN consume_date >= DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 YEAR), 'yyyyMM')
AND consume_date <= DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), 'yyyyMM') THEN consume_value ELSE 0 END) AS last_year_last_month_value,
SUM(CASE WHEN consume_date >= DATE_FORMAT(DATE_ADD(data_date, INTERVAL -MONTH(data_date) MONTH), 'yyyyMM')
AND consume_date <= DATE_FORMAT(DATE_ADD(data_date, INTERVAL -1 MONTH), 'yyyyMM') THEN consume_value ELSE 0 END) AS this_year_first_month_value,
month_id
FROM
jf_value_detail
GROUP BY
cust_id,
cust_name,
month_id
) t1
LEFT JOIN
(
--获取渠道名称
SELECT
channel_id,
channel_name
FROM
channel_info
) t2
ON t1.channel_id = t2.channel_id;
--根据条件筛选记录
DROP TABLE IF EXISTS jf_value_dhfz_show;
CREATE TABLE jf_value_dhfz_show AS
SELECT
cust_id,
cust_name,
channel_name,
consume_value,
exchange_value,
this_month_value,
last_month_value,
last_last_month_value,
last_year_this_month_value,
this_year_first_month_value,
last_year_last_month_value,
month_id
FROM
tmp_jf_value_dhfz_show
WHERE
((is_run_flag1 = 1 AND consume_value > 0) OR (is_run_flag1 = 0))
AND ((is_run_flag2 = 10 AND channel_id = 10) OR (is_run_flag2 <> 10 AND channel_id <> 10));
--删除临时表
DROP TABLE IF EXISTS tmp_jf_value_dhfz_show;
阅读全文