为了达成如题的目的,实现方法已经有了早期的两个版本:

上述两个方案中最难坚持的部分在于:要打开手机浏览器,访问相应记录网页,再按10个数字手动输入便便时间。

去年10月搞定了第三版实现方法,借助Thingspeak数据上载的timestamp,完美回避手动输入时间数据;同时脚本执行也丢去了Thingspeak;分析结果推送则通过IFTTT的webhooks发至Telegram;Thingspeak还具备利用数据作图的功能。具体如下:

便便时间记录

Telegram推送准备

统计分析和推送

% PooAnalysis
%
% thingSpeak Channel ID
ID={your_ID};

%读取最近一周的数据
[poo1,pooT] = thingSpeakRead(ID,'Fields',1,'NumDays',7);
%求这一周平均隔多少小时拉一次
weekresult=hours(mean(diff(pooT)));

clear poo1 pooT
%读取所有数据
[poo1,pooT] = thingSpeakRead(ID,'Fields',1,'NumPoints',8000);
%求整个统计期间平均隔多少小时啦一次
allresult=hours(mean(diff(pooT)));

%个性化推送字符串生成
if weekresult>=48
string2=['X桶啊你!'];
elseif weekresult>=24 & weekresult<48
string2=['你拉屎还不够勤快!'];
else
string2=['赏你朵勤快拉屎小红花!'];
end

string1=['#poo 你上周平均隔',num2str(weekresult),'小时拉一次屎,',string2,' | 整个统计期间平均隔',num2str(allresult),'小时拉一次。'];

%推送至Telegram
options = weboptions('RequestMethod','post');
response = webwrite('https://maker.ifttt.com/trigger/{your_event_name}/with/key/{your_token}', 'value1',string1, options);

给这个MATLAB Analysis加一个Time Control,设定每周执行一次。

推送效果如图:

锦上添花部分:利用Thingspeak Apps – MATLAB Visualizations绘统计图

  
% Prior to running this MATLAB code template, assign the channel ID to read
% data from to the 'readChannelID' variable. Also, assign the field ID
% within the channel that you want to read data from to plot.

% TODO – Replace the [] with channel ID to read data from:
readChannelID = {your_channel_ID};
% TODO – Replace the [] with the Field ID to read data from:
fieldID = 1;

% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the ' ' below:
% readAPIKey = ' ';

%% Read Data %%

[poo1, pooT] = thingSpeakRead(readChannelID, 'Field', fieldID, 'NumPoints', 8000, 'ReadKey', readAPIKey);

%% Visualize Data %%

[N,X]=hist(hour(pooT),0:23);
XTickN = 0 : 23;
axes('Position',[0.1 0.3 0.8 0.6],…
'XLim',[0 23],…
'XTick',XTickN,…
'Box','On')
hold on
bar(N,'FaceColor',[0.9 0.5 0.3]);
title('When you poo in a day!');
xlabel('hour');
hold off
  

效果如图:

:虽说是便便时间间隔统计,但这个思路一样可以用于记录和统计分析些别的。