statistics_report
所属分类:Linux/Unix编程
开发工具:Unix_Linux
文件大小:32KB
下载次数:5
上传日期:2010-05-17 10:23:25
上 传 者:
sunny_boy1111
说明: 中国移动统计程序的源代码,基于Linux的C语言开发,很有参考价值。
(China Mobile Statistics program' s source code, Linux-based C-language development, a good reference.)
文件列表:
report (0, 2007-11-16)
report\day.c (6597, 2007-11-14)
report\genjoudir.c (875, 2007-11-14)
report\incdel.c (5116, 2007-11-16)
report\install.sh (164, 2007-11-15)
report\main.c (8317, 2007-11-22)
report\month.c (5399, 2007-11-16)
report\readdb.c (29822, 2007-11-15)
report\readdb.pc (4659, 2007-11-15)
report\sendrec.c (11048, 2007-11-21)
report\total.c (2558, 2007-11-15)
report\unknown.c (1377, 2007-11-16)
report\week.c (5869, 2007-11-14)
软体说明:
一)实现要求:
1)每天生成日报表,到report/day目录下,文件名为日期号+.csv,如5号,即为05.csv
2)保留一个月,下个月覆盖上个月的文件
3)将每天生成的日报表文件COPY一份到sendto/day目录下,文件名固定为day.csv
4)每周生成周报表,到report/week目录下,文件名为周号+.csv,如本月的第二周,即为02.csv
5)保留一个月,下个月覆盖上个月的文件
6)将每周生成的周报表文件Copy一份到sendto/week目录下,文件名固定为week.csv
7)每月生成月报表,到report/month目录下,文件名为月号+.csv,如本月,即为11.csv
8)将每月生成的月报表文件COPY一份到sendto/month目录下,文件名固定为month.csv
9)日报表即每天的0时,统计生成昨天的报表
10)周报表即当前时间为周一时,统计上一周的数据
11)月报表即当前时间为本月1号,统计上一月的数据
12)日报表要在每天的报表的第一行第一列写入日期,如2007/11/11
13)周报表要在每周的报表的第一行第一列写入日期,如2007/11/11
14)月报表要在每月的报表的第一行第一列写入日期,如2007/11
15)统计报表数据由行(地区),列(模板)二维数据组成,模板要又分为注册用户总数,新增/退订/发送/接收四类数据
16)数据中间有逗号分隔,文件后缀为.csv,即用户用EXCEL软体打开后,即可看到自动转换后的EXCEL数据
数据统计原始格式如下:
2007-11-09,统计项目,南昌,抚州,九江,上饶,宜春,吉安,赣州,景德镇,萍乡,新余,鹰潭,全省
总,当前注册用户总数,1244***,48311,21115,57895,14603,16616,59184,34146,15624,15432,10514,417938
,日新增用户数,15,0,0,215,0,0,65,0,0,0,0,295
,日退订用户数,0,0,15,5,0,0,0,10,0,0,0,30
,日发送邮件总数(含WEB/WAP/SMTP),163,118,21,111,10,140,975,0,0,396,7,1941
,日接收邮件总数(含WEB/WAP/POP3),527,137,18,109,11,124,186,2,1,76,14,1205
3元,套餐注册用户总数,39076,477,4447,188***,4451,1175,2***7,16172,5350,6876,1227,100796
,新增用户数,3,0,0,43,0,0,13,0,0,0,0,59
,退订用户数,0,0,3,1,0,0,0,2,0,0,0,6
,日发送邮件总数,8,0,9,1,0,0,21,0,0,1,0,40
,日接收邮件总数,1,0,10,14,0,0,3,1,0,1,0,30
6元,套餐注册用户总数,39059,476,4251,18763,4446,1173,2625,16172,5348,6876,1223,100412
,新增用户数,3,0,0,43,0,0,13,0,0,0,0,59
,退订用户数,0,0,3,1,0,0,0,2,0,0,0,6
,日发送邮件总数,8,0,9,0,0,0,21,0,0,1,0,39
,日接收邮件总数,1,0,3,2,0,0,1,1,0,1,0,9
优惠,套餐注册用户总数,17853,37472,192,874,1195,126,313,224,826,226,4184,63485
,新增用户数,3,0,0,43,0,0,13,0,0,0,0,59
,退订用户数,0,0,3,1,0,0,0,2,0,0,0,6
,日发送邮件总数,3,0,0,0,0,0,9,0,0,0,0,12
,日接收邮件总数,268,27,0,0,1,9,8,0,1,1,4,319
体验,套餐注册用户总数,267***,9389,12220,19136,4146,13371,53546,1575,4092,1244,3810,149327
,新增用户数,3,0,0,43,0,0,13,0,0,0,0,59
,退订用户数,0,0,3,1,0,0,0,2,0,0,0,6
,日发送邮件总数,1,11,3,11,1,12,912,0,0,0,0,951
,日接收邮件总数,32,4,5,13,1,0,162,0,0,0,2,219
公免,套餐注册用户总数,1712,497,5,224,365,771,53,3,8,210,70,3918
,新增用户数,3,0,0,43,0,0,13,0,0,0,0,59
,退订用户数,0,0,3,1,0,0,0,2,0,0,0,6
,日发送邮件总数,143,107,0,99,9,128,12,0,0,394,7,899
,日接收邮件总数,225,106,0,80,9,115,12,0,0,73,8,628
二)环境说明
1)安装在LINUX上
2)连接数据库部份依赖于ORACLE的动态连接库
3)基本目录如下:
bin目录存放可执行文件
file目录存放下载后的文件及地区号段对映表
lib目录存放ORACLE的动态连接库
network目录ORACLE的tnsname.ora文件
ocommon目录存放ORACLE的字符集文件
report目录存放生成的报表文件
sendto目录存放每天生成的报表文件,主要是提供给开发,每天产生后即删除
tmp目录存放每天生成报表临时文件,主要用途是做周/月的数据累加
说明:
file目录存放jxmcc.txt文件
jxmcc.txt文件里面是号段对映的地区市信息
lib目录存放
libclntsh.so.9.0
libwtc9.so
在程序编译和运行时动态连接
network目录存放
/home/ceno/network/admin/tnsname.ora
内容如下:
EMAIL=
(DEscrīptION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = maildb)(port = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = email)
)
)
注:HOST=maildb,是要连接的主机名,port为端口号,SERVICE_NAME为SID
以上信息要根据实际情况配置
ocommon目录存放ORACLE的字符集,如没有该字符集,在查找varchar等字符时,会出现乱码
report目录存放生成的最终报表,分成day,week,month三个目录
sendto目录存放生成的报表,分成day,week,month三个目录,每天产生的文件即放入对映的目录下,开发操作完成后,即删除
tmp目录存放存放生成的临地报表,分成day,week,month三个目录,在周统计和月统计时做累加
三)安装编译说明:
1)指定执行此程序的用户
如:
useradd ceno
2)进入该目录
cd /home/ceno
3)将扩展包解压缩于用户目录下
tar xvzf jxyd.tar.gz
4)编辑ceno用户环境变量
vi .bash_profile
加入以下内容:
export ORACLE_HOME=/home/ceno/
export ORACLE_BASE=/home/ceno/
export ORACLE_SID=email
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG=.utf8
5)编译链接
cd /home/ceno/src
sh install.sh
6)执行report
report
四)程序执行流程:
1)获得周的序列号
if ((fp=fopen("/home/ceno/log/message","rt"))==NULL)
{
printf("open file /home/ceno/log/message failed!\n");
exit(EXIT_FAILURE);
}
fscanf(fp,"%s",seq_flag_strings);
作用:
用message中的序列号控制周的文件名,即一个月中的第几周,每次到周1即自加1,如果到每月1号,自动清0
2)读取数据库
利用PRO*C调用函数read_db_to_file(),写到各个模板文件中,以便以下的程序读取
3)统计模板的用户总数,用户增减,用户收发
MailAreaTotal("/home/ceno/file/quanqiu");
UserIncDel ("create","/home/ceno/file/quanqiu","/log_mail_purchases",6);
UserIncDel ("delete","/home/ceno/file/quanqiu","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/quanqiu","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/quanqiu","/log_mail_queue_out",7);
4)读取以上生成的数据,赋值到array数组
fread_file_day(array_day);
5)将array数组中内容写入到日统计文件,即EXCEL最终文件
fwrite_file_day(array_day,seq_file_day);
6)将array数组中内容写入到临时文件,以便周统计用
fturn_array_file(array_day,seq_file_day_tmp);
7)将EXCEL最终文件COPY到sendto目录下,供开发程序调用
copy_file(seq_file_day,sendto_file_day);
8)周统计用week_buf判断,确定是周一,进行上周统计(计算累加临地目录下7天数据),序列号累加,产生周文件
9)月统计用today_buf判断,确定是本月1号,进行上月统计(计算累加临时目录下5/4周数据)
源代码
//////////////////////////////////////////////////////
//主程序main函数
//源代码文件:main.c
//////////////////////////////////////////////////////
#include
#include
#include
#include
int main ()
{
FILE *fp;
char seq_flag_strings[4];
char seq_file_day[30]={"/home/ceno/report/day/ .csv"};
char seq_file_week[30]={"/home/ceno/report/week/0 .csv"};
char seq_file_month[30]={"/home/ceno/report/month/ .csv"};
char seq_file_day_tmp[30]={"/home/ceno/tmp/day/ .txt"};
char seq_file_week_tmp[30]={"/home/ceno/tmp/week/ .txt"};
char sendto_file_day[30]={"/home/ceno/sendto/day/day.csv"};
char sendto_file_week[40]={"/home/ceno/sendto/week/week.csv"};
char sendto_file_month[40]={"/home/ceno/sendto/month/month.csv"};
int seq_flag_int;
int array_day[30][12];
int array_week[8][30][12];
int array_month[6][30][12];
char yesday_buf[3];
char today_buf[3];
char week_buf[3];
char month_buf[3];
char filename_week[7][50]={{"/home/ceno/tmp/day/1.txt"},{"/home/ceno/tmp/day/2.txt"},\
{"/home/ceno/tmp/day/3.txt"},{"/home/ceno/tmp/day/4.txt"},{"/home/ceno/tmp/day/5.txt"},\
{"/home/ceno/tmp/day/6.txt"},{"/home/ceno/tmp/day/7.txt"}};
char filename_month[5][50]={{"/home/ceno/tmp/week/1.txt"},{"/home/ceno/tmp/week/2.txt"},\
{"/home/ceno/tmp/week/3.txt"},{"/home/ceno/tmp/week/4.txt"},{"/home/ceno/tmp/week/5.txt"}};
//读取/home/ceno/log/message文件中的标识数字,并赋值给Seq_flag_strings变量
if ((fp=fopen("/home/ceno/log/message","rt"))==NULL)
{
printf("open file /home/ceno/log/message failed!\n");
exit(EXIT_FAILURE);
}
fscanf(fp,"%s",seq_flag_strings);
printf("seq_flag_strings:%s\n",seq_flag_strings);
remove("/home/ceno/file/tempfile.bak");
printf("Delete /home/ceno/file/tempfile.bak\n");
//time(NULL)-(time_t)(60*60*24)提取昨天的日期
time_t timep_yesterday=time(NULL)-(time_t)(60*60*24);
//提取当天的日期
time_t timep_today;
struct tm *p;
time(&timep_today);
p=localtime(&timep_today);
//赋值昨天的日期(yesday_buf),当天的星期几(week_buf),当天的日期(today_buf),当天所处的月份(month_buf)
strftime(yesday_buf,sizeof(yesday_buf),"%d",localtime(&timep_yesterday));
strftime(week_buf,sizeof(week_buf),"%u",localtime(&timep_today));
strftime(today_buf,sizeof(today_buf),"%d",localtime(&timep_today));
strftime(month_buf,sizeof(month_buf),"%m",localtime(&timep_today));
//将取得的昨天日期字符赋值给seq_file_day(昨天全路径文件名字符串)
seq_file_day[22]=yesday_buf[0];
seq_file_day[23]=yesday_buf[1];
//将取得的星期字符赋值给seq_file_day_tmp(1-7.txt循环文件名字符串)
seq_file_day_tmp[19]=week_buf[0];
//将取得的月份字符赋值给seq_file_month(月全路径文件名字符串)
seq_file_month[24]=month_buf[0];
seq_file_month[25]=month_buf[1];
//如果当前日期为本月1号,将seq_flag_int至0,初始化周序列号(seq_flag_int)
if(strcmp(today_buf,"01")==0)
{
seq_flag_int=0;
}
seq_flag_int=atoi(seq_flag_strings);
//打开message文件,写入周序列号,以便下次计算
if ((fp=fopen("/home/ceno/log/message","wt"))==NULL)
{
printf("open file /home/ceno/log/message failed!\n");
exit(EXIT_FAILURE);
}
//连接数据库,读用户及模板信息
printf("read_db_to_file......ing\n");
read_db_to_file();
printf("Process quanqiu template......\n");
//统计quanqiu模板数据
MailAreaTotal("/home/ceno/file/quanqiu");
UserIncDel ("create","quanqiu","/log_mail_purchases",6);
UserIncDel ("delete","quanqiu","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/quanqiu","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/quanqiu","/log_mail_queue_out",7);
printf("Process yuan6 template......\n");
//统计yuan6模板数据
MailAreaTotal("/home/ceno/file/yuan6");
UserIncDel ("create","yuan6","/log_mail_purchases",6);
UserIncDel ("delete","yuan6","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/yuan6","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/yuan6","/log_mail_queue_out",7);
printf("Process youhui template......\n");
//统计youhui模板数据
MailAreaTotal("/home/ceno/file/youhui");
UserIncDel ("create","youhui","/log_mail_purchases",6);
UserIncDel ("delete","youhui","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/youhui","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/youhui","/log_mail_queue_out",7);
printf("Process tiyan template......\n");
//统计tiyan模板数据
MailAreaTotal("/home/ceno/file/tiyan");
UserIncDel ("create","tiyan","/log_mail_purchases",6);
UserIncDel ("delete","tiyan","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/tiyan","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/tiyan","/log_mail_queue_out",7);
printf("Process gongmian template......\n");
//统计youhui模板数据
MailAreaTotal("/home/ceno/file/gongmian");
UserIncDel ("create","gongmian","/log_mail_purchases",6);
UserIncDel ("delete","gongmian","/log_mail_purchases",6);
MailRemoteLocal (" remote ","/home/ceno/file/gongmian","/log_mail_queue_out",8);
MailRemoteLocal (" local ","/home/ceno/file/gongmian","/log_mail_queue_out",7);
printf("Process day report......\n");
//统计日报表信息
//调用函数fread_file_day,读统计数据到Array_day数组
fread_file_day(array_day);
//调用函数fwrite_file_day,Array_day数组信息到report日报中
fwrite_file_day(array_day,seq_file_day);
printf("Write to %s.\n",seq_file_day);
//调用函数fturn_array_file,将Array_day数组信息写入tmp文件中,以便下次计算周报
fturn_array_file(array_day,seq_file_day_tmp);
printf("Write to %s.\n",seq_file_day_tmp);
//
copy_file(seq_file_day,sendto_file_day);
printf("Copy to %s.\n",sendto_file_day);
//判断是否是星期1,如果是星期一,执行周统计报告
if(week_buf[0]=='1')
{
printf("Process week report......\n");
seq_flag_int=atoi(seq_flag_strings)+1;
seq_file_week[24]=seq_flag_int+48;
seq_file_week_tmp[20]=seq_flag_int+48;
fread_file_week(array_week[0],filename_week[0]);
fread_file_week(array_week[1],filename_week[1]);
fread_file_week(array_week[2],filename_week[2]);
fread_file_week(array_week[3],filename_week[3]);
fread_file_week(array_week[4],filename_week[4]);
fread_file_week(array_week[5],filename_week[5]);
fread_file_week(array_week[6],filename_week[6]);
//根据三维数组Array_week,将二维数据总和写入Array_week[7]中
week_sum(array_week);
//将周统计数据写入report周报中
fwrite_file_week(array_week[7],seq_file_week);
printf("Write to %s.\n",seq_file_week);
//将周统计矩阵数据写入tmp周报中
fturn_array_file(array_week[7],seq_file_week_tmp);
printf("Write to %s.\n",seq_file_week_tmp);
copy_file(seq_file_week,sendto_file_week);
printf("Copy to %s.\n",sendto_file_week);
}
//判断是否是本月1日,如果是本月1日,执行月统计报告
if(strcmp(today_buf,"01")==0)
{
printf("Process month report......\n");
fread_file_month(array_month[0],filename_month[0]);
fread_file_month(array_month[1],filename_month[1]);
fread_file_month(array_month[2],filename_month[2]);
fread_file_month(array_month[3],filename_month[3]);
fread_file_month(array_month[4],filename_month[4]);
//根据三维数组Array_month,将二维数据总和写入Array_month[5]中
month_sum(array_month);
//将月统计数据写入report月报中
fwrite_file_month(array_month[5],seq_file_month);
printf("Write to %s.\n",seq_file_month);
//
copy_file(seq_file_month,sendto_file_month);
printf("Copy to %s.\n",sendto_file_month);
}
//关闭文件
fprintf(fp,"%d",seq_flag_int);
fclose(fp);
return 0;
}
//////////////////////////////////////////////////////
//源代码文件:readdb.c
//////////////////////////////////////////////////////
# include
# include
# include
EXEC SQL INCLUDE SQLCA;
void sql_error(char *msg)
{
printf("\n%s %s\n", msg,(char *)sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK RELEASE;
exit(0);
}
void read_db_to_file()
{
EXEC SQL INCLUDE sqlca;
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL WHENEVER SQLERROR DO sql_error(" 〈ERROR〉 ");
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR oraCN[30];
EXEC SQL END DECLARE SECTION;
strcpy(oraCN.arr,"umail/umail@email");
oraCN.len = strlen(oraCN.arr);
oraCN.arr[oraCN.len]='\0';
EXEC SQL CONNECT :oraCN;
printf("\n [OK Connected!] ");
void init();
FILE *fp_tiyan,*fp_quanqiu,*fp_youhui,*fp_gongmian,*fp_yuan6;
char username[50];
char purchase_name[50];
char cNewLine='\n';
if((fp_tiyan=fopen("/home/ceno/file/tiyan","wt+"))==NULL)
{
printf("open file /home/ceno/file/tiyan failed\n");
exit(EXIT_FAILURE);
}
if((fp_quanqiu=fopen("/home/ceno/file/quanqiu","wt+"))==NULL)
{
printf("open file /home/ceno/file/quanqiu failed\n");
exit(EXIT_FAILURE);
}
if((fp_youhui=fopen("/home/ceno/file/youhui","wt+"))==NULL)
{
printf("open file /home/ceno/file/youhui failed\n");
exit(EXIT_FAILURE);
}
if((fp_gongmian=fopen("/home/ceno/file/gongmian","wt+"))==NULL)
{
printf("open file /home/ceno/file/gongmian failed\n");
exit(EXIT_FAILURE);
}
if((fp_yuan6=fopen("/home/ceno/file/yuan6","wt+"))==NULL)
{
printf("open file /home/ceno/file/yuan6 failed\n");
exit(EXIT_FAILURE);
}
EXEC SQL declare tiyan_cursor cursor for
select t1.username from email_users t1,business_account t2,BUSINESS_PURCHASE t3 where t1.userid=t2.USER_ID and t2.BUSINESS_ACCOUNT_ID=t3.business_account_id and t3.purchase_name like 'tiyan' and not exists (select null from users_6yuan where users_6yuan.username =t1.username);
EXEC SQL open tiyan_cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
while(1)
{
EXEC SQL fetch tiyan_cursor into :username;
fputs(username,fp_tiyan);memset(username,' ',50);
fputc(cNewLine,fp_tiyan);
}
EXEC SQL close tiyan_cursor;
EXEC SQL declare quanqiu_cursor cursor for
select t1.username from email_users t1,business_account t2,BUSINESS_PURCHASE t3 where t1.userid=t2.USER_ID and t2.BUSINESS_ACCOUNT_ID=t3.business_account_id and t3.purchase_name like 'quanqiu' and not exists (select null from users_6yuan where users_6yuan.username =t1.username);
EXEC SQL open quanqiu_cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
while(1)
{
EXEC SQL fetch quanqiu_cursor into :username;
fputs(username,fp_quanqiu);memset(username,' ',50);
fputc(cNewLine,fp_quanqiu);
}
EXEC SQL close quanqiu_cursor;
EXEC SQL declare youhui_cursor cursor for
select t1.username from email_users t1,business_account t2,BUSINESS_PURCHASE t3 where t1.userid=t2.USER_ID and t2.BUSINESS_ACCOUNT_ID=t3.business_account_id and t3.purchase_name like 'youhui' and not exists (select null from users_6yuan where users_6yuan.username =t1.username);
EXEC SQL open youhui_cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
while(1)
{
EXEC SQL fetch youhui_cursor into :username;
fputs(username,fp_youhui);memset(username,' ',50);
fputc(cNewLine,fp_youhui);
}
EXEC SQL close youhui_cursor;
EXEC SQL declare gongmian_cursor cursor for
select t1.username from email_users t1,business_account t2,BUSINESS_PURCHASE t3 where t1.userid=t2.USER_ID and t2.BUSINESS_ACCOUNT_ID=t3.business_account_id and t3.purchase_name like 'gongmian' and not exists (select null from users_6yuan where users_6yuan.username =t1.username);
EXEC SQL open gongmian_cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
while(1)
{
EXEC SQL fetch gongmian_cursor into :username;
fputs(username,fp_gongmian);memset(username,' ',50);
fputc(cNewLine,fp_gongmian);
}
EXEC SQL close gongmian_cursor;
EXEC SQL declare yuan6_cursor cursor for
select t1.username from email_users t1,business_account t2,BUSINESS_PURCHASE t3 where t1.userid=t2.USER_ID and t2.BUSINESS_ACCOUNT_ID=t3.business_account_id and t3.PURCHASE_NAME='quanqiu' and createtime
# include
# include
# include
int MailAreaTotal (cha ... ...
近期下载者:
相关文件:
收藏者: