4

I'm creative a forum and want to calculate the frequency of new posts per day. So, each post has timestamps:

$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;

What calculation do I do to find out how often posts are submitted per day. Example final output:

echo 'Every '. $frequency .' day(s)';
Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155

2 Answers2

4

You can maybe try something like this :

$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;

// I add all the value in an array then sort the array to get the min and max value
$date_array = [$post_1, $post_2, $post_3, $post_4];
sort($date_array);

// Now I can select the min date and the max date
$min_date = $date_array[0];
$max_date = $date_array[count($date_array) - 1];

// I calculate the diff to get the number of day during this period
$datediff = $max_date - $min_date;

// I divide this value with the number or article post during this period
$frequency = $datediff / count($date_array);

// Now I transform this value in number of day
$frequency = round($frequency / (60 * 60 * 24));

With your example, this is what you got :

  • Number of articles : 4
  • Min date : 2018-03-26
  • Max date : 2018-05-12
  • Number of day of the period : 46
  • Frequency : 12

That sound good for me with those value , one article every 12 days.

Is it what you are looking for?

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
1

assuming you want the general frequency:

  • frequency = 1 / period
  • period = average time between two posts = time between oldest and newest post / number of post - 1
  • time between oldest and newest post = newest post - oldest post

In your example:

$post_1 = 1526083200;
$post_2 = 1524083200;
$post_3 = 1523083200;
$post_4 = 1522083200;
  • time between oldest and newest posts = 1526083200 - 1522083200 = 4000000 seconds = 46,2962963 Days
  • period = 46,2962963/3 = 15.4320987667 Days (There is on average 15 days between two posts)
  • frequency = 1 / 15.4320987667 = 0.06479999999 (There is on average one post each 0.0648 Days)
Kepotx
  • 1,095
  • 12
  • 26