博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
再次更新
阅读量:6451 次
发布时间:2019-06-23

本文共 9779 字,大约阅读时间需要 32 分钟。

#!/bin/sh################################################                                             ##  author:lishujun                            ##  date:2013-4-11                             ##  use:$orderdetail 2013-4-11                 ##                                             ################################################### load Library ###. /www/log/stat/db_alias. /www/log/stat/public_funcinit_date $1init_db### define global variable ###bookStatTable='book_order'bookNameFile='./tmp/book_name_2013'orderDetailFile='./tmp/order_detail_2013'cpBookFile='./tmp/cp_book'clickedNumberFile='./tmp/click_number'tempDataFile='./tmp/data'scriptFile='./tmp/sql_script'### functions ###cleanTemporaryFiles(){        echo clean temporary files...        rm $bookNameFile        rm $orderDetailFile        rm $cpBookFile        rm $clickedNumberFile        rm $tempDataFile        rm $scriptFile}executeSql(){        echo writing to database...        cat $scriptFile | statdb -f}loadDataToFiles(){        echo load data...        #load basic info : bookId, bookName, author, class, chapCount        echo "select id,bookname,author,class,num_chapter from bc_bookinfos" |bookdb -s|piconv -f utf8 -t gb2312 >$bookNameFile        #load cp books: cpId, bookId        echo "select cpid,bid from bc_book_charge_cp_bid" |bookdb -s|piconv -f utf8 -t gb2312 >$cpBookFile         #load book click number        echo "select id,num_today_click from bc_bookinfos_ext_stat" |bookdb -s|piconv -f utf8 -t gb2312 >$clickedNumberFile         #load order info : userId, bookId, chapId, orderAmount, size, date, time, chargeable        #for i in `echo "show tables like 'bc_user_charged_list_wap%';"|booknewdb -s`        #do        #       sql="select userid,bid,chapterid,price,size,from_unixtime(charged_time),use_curr from $i"        #                       sql=$sql" where from_unixtime(charged_time) like '$stat_date%' "        #        #       echo $sql | booknewdb -s        #       #echo $sql        #done >$orderDetailFile        #load order info : userId, bookId,chapId, orderAmount, size, date, time, chargeable (from merge!!!)        sql="select userid,bid,chapterid,price,size,from_unixtime(charged_time),use_curr from bc_user_charged_list_wap_merge"                               sql=$sql" where from_unixtime(charged_time) like '$stat_date%' "        echo $sql | booknewdb -s |piconv -f utf8 -t gb2312 > $orderDetailFile}stat(){        echo stat...        awk -v statDate=$stat_date \            -v bookStatTable=$bookStatTable \            -v bookNameFile=$bookNameFile \            -v cpBookFile=$cpBookFile \            -v clickedNumberFile=$clickedNumberFile \            -v tempDataFile=$tempDataFile \            -v scriptFile=$scriptFile \        '                ### util functions ###                function isVaild(value)                {                        if(value > 0)                                return 1                        else                                return 0                }                function computeARPU(bookId,books)                {                        if(isVaild(books[bookId,"orderUserCount"]) == 0)                        {                                return 0                        }                        return books[bookId,"orderAmount"] / books[bookId,"orderUserCount"]                }                function readerConversionRate(bookId,books)                {                        if(isVaild(books[bookId,"clickedUserCount"]) == 0)                        {                                return 0                        }                        return books[bookId,"readerCount"] / books[bookId,"clickedUserCount"]                }                function deepReaderConversionRate(bookId,books)                {                        if(isVaild(books[bookId,"readerCount"]) == 0)                        {                                return 0                        split(names,nameArray,",")split(names,nameArray,",")}                        return books[bookId,"deepReaderCount"] / books[bookId,"readerCount"]                }                function readerOrderRate(bookId,books)                {                        if(isVaild(books[bookId,"readerCount"]) == 0)                        {                                return 0                        }                        retunrn books[bookId,"orderUserCount"] / books[bookId,"readerCount"]                 }                function browserOrderRate(bookId,books)                {                        if(isVaild(books[bookId,"cickedUserCount"]) == 0)                        {                                return 0                        }                        retunrn books[bookId,"orderUserCount"] / books[bookId,"clickedUserCount"]                 }                function lowerStyle(oldStr)                {                        newStr = ""                        for(j=1;j <= length(oldStr);j++)                        {                                oneChar = substr(oldStr,j,1)                                if(match(oneChar,/[A-Z]/) == 0)                                {                                        newStr = newStr "" oneChar                                }                                else                                {                                        if(substr(oldStr,j)=="Id")                                        {                                                newStr = newStr "" tolower(oneChar)                                        }                                        else                                        {                                                newStr = newStr "_" tolower(oneChar)                                        }                                }                        }                        return newStr                }                function getSubArrayNames()                {                        #for print                        #names = "authorId,classId,cpId,chapCount,statDate,orderAmount,orderCount,orderUserCount,orderChapCount,"                        #names = names "readerCount,deepReaderCount,clickedUserCount,"                        #names = names "ARPU,readerConversionRate,deepReaderConversionRate,readerOrderRate,browserOrderRate"                        #for insert                        names = "authorId,classId,cpId,statDate,orderAmount,orderCount,orderUserCount,"                                   names = names "readerCount,deepReaderCount,clickedUserCount,"                                                                              names = names "ARPU,readerConversionRate,deepReaderConversionRate,readerOrderRate,browserOrderRate"                        return names                }                function makeDeleteSql(bookId)                {                        sql = "delete from "bookStatTable" where bookid=" bookId " and stat_date=\"" statDate "\";"                        print sql >> scriptFile                }                function makeInsertSql(bookId,books)                {                        names = getSubArrayNames()                        split(names,nameArray,",")                        filedNames = ""                        filedValues = ""                        for(i in nameArray)                        {                                if(nameArray[i] == "ARPU")                                {                                        nameArray[i] = "arpu"                                }                                filedNames = filedNames "" lowerStyle(nameArray[i]) ","                                filedValues = filedValues "\"" books[bookId,nameArray[i]] "\","                        }                        filedNames = filedNames"bookid"                        filedValues = filedValues""bookId                        sql = "insert into " bookStatTable "(" filedNames ") values(" filedValues ");"                        print sql >> scriptFile                }                function printBookStatInfo(bookId,books)                {                        names = getSubArrayNames()                        split(names,nameArray,",")                        printf("\n\nbookId=%s,detail:\n",bookId) >> tempDataFile                        for(i in nameArray)                        {                                printf("%s is %s\n",nameArray[i],books[bookId,nameArray[i]]) >> tempDataFile                        }                }                ### make books ###                BEGIN{                        #load cpId                        while(getline
0) { #compute ARPU and Rates books[bookId,"ARPU"] = computeARPU(bookId,books) books[bookId,"readerConversionRate"] = readerConversionRate(bookId,books) books[bookId,"deepReaderConversionRate"] = deepReaderConversionRate(bookId,books) books[bookId,"readerOrderRate"] = readerOrderRate(bookId,books) books[bookId,"browserOrderRate"] = browserOrderRate(bookId,books) #make insert SQL statement #printBookStatInfo(bookId,books) makeDeleteSql(bookId) makeInsertSql(bookId,books) } } } ' $orderDetailFile}main(){ cleanTemporaryFiles loadDataToFiles stat executeSql echo done}#call main functionmain

 

转载于:https://www.cnblogs.com/code-style/archive/2013/04/16/3024359.html

你可能感兴趣的文章
如何在linux系统下配置共享文件夹,如何在windows和Linux系统之间共享文件夹.doc
查看>>
thinkpad装linux无线网卡驱动,ThinkPad E530 Fedora 20 下无线网卡驱动的安装
查看>>
linux操作系统加固软件,系统安全:教你Linux操作系统的安全加固
查看>>
linux中yum源安装dhcp,24.Linux系统下动态网络源部署方法(dhcpd)
查看>>
linux屏幕复制显示出来的,linux – stdout到gnu屏幕复制缓冲区
查看>>
一起学Shell(十)之可称植性议题与扩展
查看>>
部署Ganglia监控Hadoop&Hbase
查看>>
gitlab的用户使用手册
查看>>
论Optimizer的工作模式ALL_ROWS&FIRST_ROWS
查看>>
生产环境高并发MySQL SQL语句优化案例
查看>>
Lync 小技巧-24-PDF 加密文件-转-Word-操作手册
查看>>
ASP.NET性能优化之分布式Session
查看>>
TaffyDB Introduction
查看>>
转载:《TypeScript 中文入门教程》 16、Symbols
查看>>
JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记4
查看>>
C#技术------垃圾回收机制(GC)
查看>>
漫谈并发编程(三):共享受限资源
查看>>
【转】github如何删除一个仓库
查看>>
Linux系统编程——进程调度浅析
查看>>
大数据Lambda架构
查看>>