文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>群活跃统计程序

群活跃统计程序

时间:2010-08-09  来源:vivieu

群活跃统计程序

程序功能要求:
统计群成员活动;
查询群成员活动;
增删成员;
// 增删活动;

快捷操作
程序类型为“控制台”,可以dos命令方式调用。
灵活性
将文件 group.ini 中的元素名定义在 daydayup.ini 中,用户可以根据喜好定义群成员名的简写、活动名和简写。

daydayup.ini
定义数据文件中的关键字。
示例

[Active]
; 发起讨论
L=Launch
; 参与讨论
D=Discuss
; 解决问题
R=Resolve
; 共享程序
SC=ShareCode
; 共享电子书
SE=ShareEBook
; 共享软件
SS=ShareSoftware
; 推荐学习方法、网站,对群友有益的东西。
E=Recommend
; 发黄色图片、笑话
Y=Yellow
; 其它影响身心建议的垃圾
G=Garbage

[member]
pz=鹏振
bb=波波
qq=邱邱

group.ini
用于记录群活动数据。(也可以用csv,更理想的选择是xml)
示例

[Global]
members=2

[波波]

Launch=4
Discuss=15
Resolve=2
ShareCode=0
ShareEBook=2
ShareSoftware=0
Recommend=1
Yellow=2
Garbage=1
[鹏振]
Launch=10
Discuss=20
Resolve=2
ShareCode=2
ShareEBook=1
ShareSoftware=4
Recommend=0
Yellow=1
Garbage=0
[邱邱]
...


Code:

/*
群活动统计程序

用法:
ddu [-m <member> [-dn]] [-a <active>] [-n <increment>]
ddu /?
说明:
ddu 程序名,含意是daydayup
member 群成员名(简记符)
active 活动(简记符)
increment 活动数量,默认为+1
/? 帮助

关键字:
控制台程序编写之参数处理;
ini文件操作 api;

ver1.0
2010年8月8日
pz

疑问:
stru_param_tag 位域定义时,最先定义的位 应该为msb,但这里却是lsb.
*/
/*

Ver1.0 不支持member、active的简写,不需要daydayup.ini文件。


示例:
ddu -m pz -a Y -n 2
成员pz的Yellow值 +2。
若pz不存在,则建立之。

ddu -m pz
查询成员pz的活动统计情况

ddu
查询所有成员的活动统计情况

ddu -m pz -dn
删除成员pz

*/
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define DAT_FILE_PATH ".\\group.ini"
#define CFG_FILE_PATH ".\\daydayup.ini"
#define SEC_MEM_ID0 1 /* 第一个成员段的section index */

#define GetIniStr(section, key, _buf) ::GetPrivateProfileString(section, key, "0", _buf, 256, DAT_FILE_PATH)
#define SetIniStr(section, key, _buf) ::WritePrivateProfileString(section, key, _buf, DAT_FILE_PATH)
#define GetIniInt(section, key) ::GetPrivateProfileInt(section, key, 0, DAT_FILE_PATH)
void SetIniInt(const char *section, const char *key, int val)
{
    char buf[10];
    itoa(val, buf, 10);
    ::WritePrivateProfileString(section, key, buf, DAT_FILE_PATH);
}


typedef unsigned char uchar;
typedef unsigned short word;
typedef unsigned int dword;

#pragma pack(1)
struct stru_param_tag{
    word sw_member:1;
    word val_member:1;
    word sw_delmember:1;
    // word :0; // bug ?

    word sw_active:1;
    word val_active:1;

    word sw_increment:1;
    word val_increment:1;
}stru_param;
#pragma pack()

typedef enum en_command_tag{
    eCMD_REPORT_ALL = 0,
    eCMD_REPORT_MEM = 0x0003,

    eCMD_STATISTIC_DEF = 0x001b,
    eCMD_STATISTIC = 0x007b,

    eCMD_DELETE_NAME = 0x0007,
}E_COMMAND;

// params
string sMember;
string sActive;
int iIncrement;

// ini file
int iSections;
int iKeys;
char cSectionNames[1024];
vector<string> vSectionNames;
char cSection[1024];
vector<string> vSection;
int iKeyVal;

int Distribute(char cSN[], int size, vector<string> &vSN);

int main(int argc, char *argv[])
{
    int i, j;
    E_COMMAND eCmd;
    
    char buf[256];
    string sTmp;

    int iMembers;
    int iAttributes;

    string sSection;
    string sKey;
    string sKeyValue;
    
    // 参数分析
    for(i=1; i<argc; i++)
    {
        sTmp = argv[i];

        // 独立的命令开关
        if( "-dn" == sTmp)
        {
            stru_param.sw_delmember = 1;                
        }
        else// 需要参数的命令开关
        {
            if(argc-1 == i)
            {
                cout<<sTmp<<" 缺少参数!"<<endl;
                system("pause>nul");
                return -1;
            }
            
            if("-m" == sTmp)
            {
                stru_param.sw_member = 1;
                stru_param.val_member = 1;
                sMember = argv[++i];

                // cout<<sMember<<endl;
                //cout<<"cmd:"<<*(word*)&stru_param<<endl;
            }
            else if("-a" == sTmp)
            {
                stru_param.sw_active = 1;
                stru_param.val_active = 1;
                sActive = argv[++i];
                // cout<<sActive<<endl;
                //cout<<"cmd:"<<*(word*)&stru_param<<endl;
            }
            else if("-n" == sTmp)
            {
                stru_param.sw_increment = 1;
                stru_param.val_increment = 1;
                iIncrement = atoi(argv[++i]);
                // cout<<iIncrement<<endl;
            }
        }
    }// end for


    eCmd = *(E_COMMAND*)&stru_param; // cast
    //cout<<"cmd:"<<*(word*)&stru_param<<endl;

    // 取得所有的小节名
    ::GetPrivateProfileSectionNames(cSectionNames, 1024, DAT_FILE_PATH);
    iSections = Distribute(cSectionNames, 1024, vSectionNames);
    //cout<<"iSections:"<<iSections<<endl;

    switch(eCmd)
    {
    case eCMD_REPORT_ALL:        
        cout<<"eCMD_REPORT_ALL"<<endl;
        iMembers = GetIniInt("Global", "members");
        iAttributes = GetIniInt("Global", "attributes");
        if(iSections != iMembers+SEC_MEM_ID0)
        {
            cout<<"ini文件内容有误:成员数_总段数 = "<<iMembers<<"_"<<iSections <<endl;
        }

        for(i=0; i<iMembers; i++)
        {
            ::GetPrivateProfileSection(vSectionNames[SEC_MEM_ID0+i].c_str(), cSection, 1024, DAT_FILE_PATH);
            iKeys = Distribute(cSection, 1024, vSection);

            cout<<vSectionNames[SEC_MEM_ID0+i]<<endl;                
            for(j=0; j<iKeys; j++)
            {
                cout<<vSection[j]<<endl;
            }
            cout<<"------------------"<<endl;
        }

    break;
    case eCMD_REPORT_MEM:
        cout<<"eCMD_REPORT_MEM"<<endl;

        ::GetPrivateProfileSection(sMember.c_str(), cSection, 1024, DAT_FILE_PATH);
        iKeys = Distribute(cSection, 1024, vSection);

        if(0 == iKeys)
        {
            cout<<"未找到 ["<<sMember<<"]"<<endl;
            break;
        }    

        cout<<sMember<<endl;                
        for(j=0; j<iKeys; j++)
        {
            cout<<vSection[j]<<endl;
        }
        cout<<"------------------"<<endl;
        
    break;
    case eCMD_STATISTIC_DEF:
        //cout<<"eCMD_STATISTIC_DEF "<<endl;
        iIncrement = 1;
        /* fall through */
    case eCMD_STATISTIC:
        //cout<<"eCMD_STATISTIC "<<endl;
        iKeyVal = GetIniInt(sMember.c_str(), sActive.c_str());
        SetIniInt(sMember.c_str(), sActive.c_str(), iKeyVal+iIncrement);
    break;
    case eCMD_DELETE_NAME:
        //cout<<"eCMD_DELETE_NAME "<<endl;
        SetIniStr(sMember.c_str(), NULL, NULL);
    break;
    default:
        cout<<ios::hex<<*(word*)&eCmd<<"参数不合法"<<endl;
        system("pause>nul");
    break;
    }

    return 0;
}

int Distribute(char cSN[], int size, vector<string> &vSN)
{
    int i;
    string item = "";
    for(i=0; i<size-1; i++)
    {
        if(0 == cSN[i])
        {
            if(item != "")
                vSN.push_back(item);
            item = "";
            if(0 == cSN[i+1]) // double '\0'
                break;
        }
        else
            item+=cSN[i];        
    }
    
    return vSN.size();
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载