B3M38SPD seminar project - beehive monitor with LoRa reporting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spd-lorabees/Docs/asciiplot.c

124 lines
12 KiB

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <float.h>
#define print printf
void graph(uint32_t width, uint32_t height, float *values, uint32_t count)
{
float max = FLT_MIN;
float min = FLT_MAX;
for (int i = 0; i < count; i++) {
float f = values[i];
if (f < min) min = f;
if (f > max) max = f;
}
float ystep = (max - min) / (float)height;
int xstep = count / width;
printf("min %f max %f\r\n", min, max);
for (int i = height-1; i >= 0; i--) {
float thr = i*ystep;
for (int j = 0; j < width; j++) {
float acu = 0;
int cnt = 0;
for (int k = j*xstep; k < (j+1)*xstep && k < count; k++, cnt++) {
acu += values[k];
}
//acu /= (float)cnt;
float sample = acu;//values[j*xstep];
if (sample >= thr) {
print("#");
} else {
print(" ");
}
}
print("\r\n");
}
}
void graphx(uint32_t width, uint32_t height, float *values, uint32_t count, float xbin)
{
printf("Count: %d\r\n", count);
float max = FLT_MIN;
float min = FLT_MAX;
for (int i = 0; i < count; i++) {
float f = values[i];
if (f < min) min = f;
if (f > max) max = f;
}
printf("Min: %f, Max: %f\r\n", min, max);
float ystep = (max - min) / height;
int xstep = count / width;
printf("Step: Y %f, X %d\r\n", ystep, xstep);
for (int i = height-1; i >= 0; i--) {
float thr = i*ystep;
printf("%9.3f ", thr);
for (int j = 0; j < width; j++) {
float sample = values[j*xstep];
if (sample >= thr) {
printf("#");
} else {
printf(" ");
}
}
printf("\r\n");
}
printf(" ");
for (int j = 0; j < width; j += 9) {
printf("^%-7.1f ", j*xstep*xbin);
}
printf("\r\n");
}
void graph_notxt(uint32_t width, uint32_t height, float *values, uint32_t count)
{
float max = FLT_MIN;
float min = FLT_MAX;
for (int i = 0; i < count; i++) {
float f = values[i];
if (f < min) min = f;
if (f > max) max = f;
}
float ystep = (max - min) / height;
int xstep = count / width;
for (int i = height-1; i >= 0; i--) {
float thr = i*ystep;
for (int j = 0; j < width; j++) {
float sample = values[j*xstep];
if (sample >= thr) {
printf("#");
} else {
printf(" ");
}
}
printf("\r\n");
}
}
int main() {
float values[] = {
7.9122, 15.4885, 14.0256, 11.1204, 5.1178, 2.6390, 7.9967, 8.5742, 10.3803, 30.2162, 14.8622, 11.3653, 6.8459, 4.3735, 3.9876, 5.9205, 10.6627, 7.7333, 9.6134, 8.2269, 5.7907, 4.3758, 4.5274, 6.7128, 8.7482, 7.9532, 9.2303, 8.2405, 6.5423, 6.6210, 6.8379, 7.5010, 10.1984, 9.7803, 8.4056, 7.1655, 7.0155, 7.6882, 8.8738, 8.3281, 9.3178, 7.4093, 7.1354, 6.2562, 6.8689, 9.0996, 10.5141, 10.5319, 7.7416, 5.1560, 4.4137, 4.3777, 6.3691, 9.2786, 10.5320, 10.2588, 7.8968, 3.2069, 2.3211, 1.8063, 5.3873, 8.1751, 7.4886, 10.7107, 15.6457, 5.6788, 3.3284, 3.1329, 2.9618, 2.5223, 3.9515, 5.8041, 7.9539, 5.8484, 5.4875, 4.5542, 2.8538, 1.9458, 2.8056, 4.2853, 5.7298, 7.7727, 6.0443, 4.9757, 3.8207, 3.3878, 3.6531, 3.5916, 5.3526, 6.9882, 5.1091, 4.1503, 4.1155, 3.4408, 3.8566, 3.6218, 1.2501, 6.4602, 3.7347, 4.1925, 4.7306, 4.6737, 4.0282, 1.8586, 4.3765, 2.3229, 1.0740, 2.3407, 3.3380, 3.0223, 2.9634, 2.2029, 3.0592, 1.8562, 1.2132, 1.8783, 3.0253, 3.0674, 1.9376, 1.2596, 4.0257, 2.8297, 1.7539, .4097, 1.8720, 1.4616, 1.6670, 3.7295, 5.8980, 4.8732, 5.3492, 3.6543, 3.3389, 2.4343, 2.6613, 2.9141, 5.3350, 4.2145, 5.1110, 4.5290, 3.7612, 2.4055, 2.1686, 2.9036, 4.3619, 5.4208, 4.4054, 3.6352, 3.8976, 2.9880, 2.9534, 3.5572, 4.3405, 4.1525, 3.3131, 3.1148, 3.4181, 2.9501, 3.4882, 3.7625, 3.9005, 4.8383, 3.6994, 3.3247, 3.5891, 3.1072, 3.4966, 3.6136, 1.2855, 2.2557, 1.8968, 2.2898, 2.8533, 2.6284, 2.8373, 2.5571, 1.2642, 1.2734, .5556, 1.5960, 2.1394, 1.9587, 1.8949, .5686, 2.1763, 1.0300, 1.0305, .4355, 1.0321, .6552, .5473, 2.1480, 4.8649, 6.6942, 3.9553, 2.9643, 2.3177, 1.5238, 1.4269, 1.3847, 3.4890, 5.0525, 4.3353, 3.6110, 1.9356, 1.2295, 1.3110, 1.6193, 3.4029, 3.8891, 4.0635, 3.7704, 3.1042, 2.7323, 3.0874, 3.2893, 3.5264, 2.7416, 2.7293, 2.9464, 3.1851, 2.4064, 2.8488, 3.5234, 4.0049, 3.6930, 4.0918, 3.6662, 3.2726, 3.6437, 3.6651, 4.8180, 2.6633, 3.3513, 1.7259, 2.3791, 2.7765, 2.8950, 3.2874, 3.9055, .8976, .4165, 1.3985, 1.9336, 1.7956, 2.0202, 2.0239, 2.4125, .8405, 1.7271, 1.3820, .1073, 1.1518, 1.2711, .1840, 3.4166, 8.9001, 3.7830, 2.0859, 2.7311, 2.8627, 1.8624, 1.5272, .7393, 5.6784, 8.5273, 2.9838, 2.9936, 3.2163, 3.1172, 3.1722, 3.0817, 4.9154, 4.9335, 4.8573, 4.4012, 3.7569, 3.6366, 3.3958, 4.5656, 4.9252, 2.0287, 3.1920, 3.3289, 3.4142, 3.1629, 3.1271, 4.5701, 1.5533, 3.2518, 3.8073, 2.9001, 2.8968, 3.8769, 4.1020, 7.8684, 2.1236, 1.6868, 1.7023, 2.2462, 1.8722, 2.9638, 3.5711, 8.4603, 4.0744, .3085, .5369, .8964, 1.2363, 2.7718, 4.2328, 10.8456, 4.6507, .4370, .6030, 1.2642, 1.7562, 2.0253, 1.7721, 6.1142, 1.6511, 3.9602, 2.8512, 2.2518, 1.8157, 1.7400, .4071, .4452, .8210, 3.3484, 3.3767, 3.3707, 2.5932, 1.5860, 1.6496, 1.3624, 2.1473, 2.9355, 3.3317, 2.8792, 2.7265, 1.9056, 1.8979, 2.9130, 2.1400, 2.5999, 2.7493, 2.8211, 1.9164, 2.2649, 1.6781, 3.8375, 4.0695, 1.2247, 3.4738, 3.1840, 3.0826, 3.5416, 3.7712, 4.3819, 2.6160, .7620, 2.3114, 1.9893, 2.2001, 3.1579, 3.4090, 3.6613, .3611, 1.0522, .4859, .6775, 1.8368, 2.8693, 2.7450, 1.4946, 3.0855, 1.1593, .7523, .6521, 1.6794, 1.9549, .9588, 2.2955, .7199, .9664, .6348, 2.4077, 2.7459, 1.7274, .8986, 1.1171, 2.0476, 1.8678, 2.1912, 3.5698, 3.1827, 2.5690, 1.6740, 1.2870, 2.3683, 3.3240, 3.4424, 3.6908, 3.4183, 2.3208, 2.0847, 2.1928, 2.3461, 4.0773, 4.0457, 3.5052, 3.0517, 2.4563, 3.0366, 3.5991, 2.7896, 3.0155, 2.2135, 3.4312, 3.5615, 3.1951, 4.2116, 4.5400, 3.3959, 2.1494, 1.4433, 2.8180, 2.6516, 3.5310, 4.1773, 3.6040, 3.0339, 2.3910, 1.5410, 1.7103, 1.9205, 2.7075, 2.9913, 4.9059, 2.0915, 1.7890, 1.4500, 1.3811, 1.7994, 2.4421, 1.3852, 1.4849, 1.7717, 1.4743, 2.0103, 3.3933, 3.0824, 1.2299, .6821, 1.8469, 1.0739, 1.7390, 2.8815, 4.0901, 4.5316, 3.2601, 2.0226, 1.6857, 4.0506, 3.8988, 4.4013, 5.1447, 4.4952, 3.7147, 3.4192, 3.7969, 6.2508, 5.5000, 4.7111, 5.1983, 4.4876, 3.8144, 4.3992, 2.4931, 5.2745, 4.4066, 3.3767, 4.1854, 3.6291, 3.7902, 5.3007, 5.4523, 4.8626, 4.0116, 2.7825, 3.1969, 3.4395, 4.1534, 4.7302, 3.9756, 3.3272, 3.0657, 1.5616, 1.9079, 2.0840, 3.6461, 5.0424, 5.2633, 3.7599, 2.3404, 1.5188, 1.4977, 1.8091, 2.5423, 3.9926, 4.0317
};
float values2[] = {16.4778,.0152,.0485,.0549,.0683,.0300,.0902,.0408,.0459,.0368,.0568,.1400,.0161,.0116,.0305,.0532,.0519,.0271,.0525,.0851,.0174,.0211,.0347,.0796,.0294,.0252,.1227,.0382,.0091,.0251,.0346,.0954,.0211,.0600,.0789,.0777,.0194,.0248,.0120,.0358,.0823,.0278,.0494,.1074,.0114,.0284,.0208,.0360,.0629,.0331,.0665,.0301,.0384,.0058,.0117,.0504,.0364,.0418,.1033,.0423,.0197,.0186,.0119,.0434,.0633,.0214,.0332,.0976,.0462,.0365,.0522,.0195,.0371,.0207,.0461,.0778,.0379,.0503,.0092,.0494,.0217,.0220,.0977,.1793,.0082,.0184,.0288,.0822,.0113,.0459,.0891,.0706,.0267,.0075,.0119,.0669,.0258,.0343,.0442,.1912,.0198,.0356,.0428,.0150,.1746,.0226,.1366,.0719,.0251,.0396,.0251,.0252,.0673,.0617,.0220,.1093,.0242,.0489,.0194,.0423,.0044,.0031,.1262,.0570,.0749,.0396,.0266,.0226,.0112,.0334,.0332,.0578,.0447,.0520,.0275,.0421,.0036,.0105,.0464,.1251,.0488,.0148,.0282,.0147,.0380,.0305,.1203,.1539,.0265,.0129,.0346,.0747,.0237,.0468,.0169,.0482,.0360,.0297,.0234,.0255,.0313,.0465,.0617,.0245,.0248,.0292,.0175,.0315,.3682,.0380,.0561,.0484,.0393,.0522,.0381,.0166,.0291,.0403,.0817,.0559,.0085,.0255,.0182,.0556,.0095,.0371,.0177,.0547,.0458,.0297,.0117,.0135,.0549,.0303,.0488,.0857,.0287,.0449,.0338,.0409,.0593,.0167,.0220,.0368,.0242,.0384,.0103,.0322,.0111,.0398,.0363,.0643,.0419,.0507,.0353,.0609,.0226,.0201,.0878,.1060,.0346,.0507,.0316,.0339,.0292,.0412,.1011,.1131,.0238,.0182,.0367,.0265,.4082,.0317,.0758,.0869,.0220,.0246,.0807,.0251,.0274,.0263,.0309,.0991,.0672,.0117,.0074,.0446,.0305,.0200,.0383,.0644,.0465,.0381,.0116,.0209,.0898,.0111,.0795,.0583,.0398,.0420,.0338,.0117,.0127,.0145,.0281,.0248,.0666,.0304,.0389,.0385,.0333,.0372,.0270,.1239,.0243,.0343,.0248,.1920,.0371,.0361,.0850,.1027,.0418,.0415,.0428,.0685,.0338,.0136,.0553,.0267,.0286,.0734,.0659,.0429,.1652,.0292,.0546,.0367,.0274,.0419,.0213,.0100,.0311,.0445,.0536,.0182,.0183,.0188,.0182,.0404,.0213,.0549,.0806,.0344,.0130,.0455,.0190,.0773,.0160,.0256,.0859,.0593,.0289,.0645,.0499,.0278,.0043,.0049,.0714,.1081,.0537,.0128,.0459,.0592,.0356,.0701,.0573,.1237,.0443,.0182,.0230,.5030,.0214,.0469,.0241,.0654,.0394,.0254,.0465,.0374,.0233,.0430,.0552,.1338,.0230,.0366,.0539,.0545,.0466,.0280,.1164,.0277,.0125,.0131,.0255,.0187,.0262,.0644,.0588,.0150,.0592,.0273,.0212,.0566,.0265,.0246,.1553,.0597,.0355,.0540,.0130,.0543,.0324,.0179,.0363,.1126,.0321,.0148,.0564,.0352,.0694,.0239,.0550,.0696,.0589,.0399,.0321,.0431,.0194,.0188,.0768,.0958,.0379,.0227,.0164,.4803,.0212,.0343,.0981,.1997,.0176,.0534,.0536,.0670,.0341,.0215,.0745,.0744,.0369,.0340,.0282,.0211,.0469,.0174,.0553,.0611,.0090,.0696,.0432,.0104,.0116,.0182,.0297,.0670,.0201,.0286,.0159,.0379,.0439,.0513,.1406,.0893,.0356,.0191,.0147,.0250,.0232,.0378,.0902,.2414,.0109,.0478,.0311,.0426,.0173,.0248,.0317,.0432,.0094,.0155,.0288,.0308,.0252,.0306,.0529,.1098,.0483,.0586,.0114,.2164,.0067,.0153,.1510,.0960,.0550,.0283,.0215,.0398,.0647,.0389,.0879,.0376,.0213,.0355,.0275,.0316,.0744,.0007,.0453,.1154,.0493,.0225,.0371,.0209,.0769,.0302,.1804,.0264,.0186,.0502,.0115,.0251,.0104,.0230,.0678,.0126,.0061,.0146,.0570,.0263,10.4977,.0325,.0357,.0677,.0594,.0473,.1246,.0734,.2829,.0637,.0227,.1208,.0421,.0248,.0079,.0710,.1917,.0548,.0876,.2174,.0232,.0097,.0688,.1140,.0974,.0431,.0905,.1107,.0618,.0304,.0790,.0766,.0633,.0533,.0746,.0803,.0377,.0140,.0343,.0686,.0392,.0581,.1085,.0472,.0083,.0398,.0619,.1247,.0862,.0602,.0820,.0660,.0415,.0190,.0163,.1657,.0412,.0451,.0993,.0352,.0583,.0263,.0356,.3486,2.1308,.0653,.0715,.0660,.0259,.0277,.0342,.0575,.3096,.0626,.0464,.0551,.0458,.0762,.0355,.0780,.1687,.0737,.0656,.1577,.0297,.0257,.0215,.1464,.0649,.0299,.0209,.0548,.0468,.0156,.0840,.0706,.0840,.0639,.0497,.1987,.0211,.0085,.0122,.0705,.2125,.0478,.0764,.0534,.0183,.0357,.0625,.0922,.0705,.0605,.1382,.0335,.0328,.0903,.0553,.0912,.0553,.0384,.1005,.0527,.0833,.0243,.0476,.3440,1.1950,.0332,.1074,.0858,.0193,.0560,.0424,.0669,.2699,.0684,.0244,.1469,.0187,.0470,.0772,.0854,.1347,.0910,.0994,.0795,.0520,.0181,.0723,.2011,.0774,.0537,.0226,.0793,.0558,.0019,.0427,.0652,.0725,.0439,.1101,.0955,.0251,.0352,.0288,.0919,.8730,.0536,.0816,.0720,.0503,.0419,.0363,.0913,.0796,.0497,.0819,.0468,.0356,.0362,.0586,.2251,.0551,.0504,.0704,.0073,.0559,.0509,.0634,.4504,.7419,.0232,.0317,.0718,.0487,.0100,.0238,.0738,.2188,.0619,.0496,.0686,.0286,.0336,.0283,.0623,.1322,.0171,.0627,.0620,.0272,.0548,.0038,.1845,.0873,.0520,.0968,.0589,.0471,.0640,.0500,.0724,.0442,.0194,.1255,.0823,.0191,.0596,.0522,.0829,.6633,.0759,.0396,.1256,.0412,.0347,.0547,.1141,.0819,.0357,.0489,.1018,.0555,.0128,.0362,.1604,.0836,.0159,.1187,.0317,.0347,.0211,.0322,.5518,.6692,.0552,.0864,.0543,.0290,.0205,.0123,.0869,.2125,.0593,.0122,.0484,.0552,.0379,.0305,.0644,.1563,.0313,.0671,.1229,.0208,.0405,.0668,.2046,.1025,.0834,.0945,.1341,.0342,.0309,.0130,.0446,.0416,.0057,.1114,.1764,.0219,.0602,.0621,.0762,.1253,.0503,.0721,.0623,.0430,.0611,.0700,.1406,.0429,.0138,.0697,.0430,.0422,.0750,.0539,.2063,.0796,.0583,.1218,.0568,.0115,.0178,.0421,.6342,.4985,.0429,.0699,.0679,.0568,.0318,.0504,.0281,.1852,.0656,.0991,.0821,.0375,.0374,.0144,.1010,.1036,.0345,.1205,.1436,.0588,.0393,.0771,2.3870,.0860,.0639,.0686,.0973,.0147,.0243,.0316,.0557,.0882,.0425,.1057,.1913,.0544,.0641,.0880,.0750,.1715,.0122,.1227,.0372,.0398,.0246,.0756,.1267,.0495,.0656,.1121,.0535,.0506,.0330,.0435,.2454,.0830,.0499,.0858,.0825,.0323,.0543,.0589,.9529,.4282,.0496,.0447,.1849,.0377,.0420,.0693,.0433,.2064,.0552,.0666,.1293,.0612,.0588,.0213,.1039,.0884,.0367,.0376,.1198,.0260,.0383,.0364,.4076,.1022,.0525,.0192,.0279,.0173,.0415,.0132,.0537,.0601,.0478,.0255,.0731,.0604,.0246,.0284,.1075,.1490,.0310,.0619,.0690,.0518,.0470,.0488,.1686,.0648,.0653,.0899,.0787,.0314,.0576,.0256,.2681,.0487,.0216,.0311,.0385,.0248,.0296,.0530,1.4637,.3347,.0194,.0567,.0592,.0395,.0513,.0694,.0719,.1327,.0698,.0715,.0608,.0194,.0256,.0142,.0699,.1080,.0187,.0077,.0387,.0492,.0504,.0363,.1628,.0507,.0413,.1119,.1031,.0556,.0259,.0296,.0704,.0180,.0804,.0500,.0853,.0260,.0344,.0295,.0872,.1355,.0274,.1091,.0752,.0311,.0325,.0111,.1644,.0149,.0299,.0847,.0429,.0137,.0291,.0543,.3282,.0561,.0174,.0595,.0358,.0301,.0351,.0666,3.4704};
//graph(70, 20, values, 512, 1);
graph(70, 20, values2+1, 1024-1);
return 0;
}