-5

我有以下数据:

a  , b , c   , d                 , e  , f
375, 52, 1892, http://example.com, ::1, 1308233412
341, 52, 1892, http://example.com, ::1, 1308233412
422, 52, 1892, http://example.com, ::1, 1308233417
478, 50, 1892, http://example.com, ::1, 1308233418
58, 481, 1892, http://example.com, ::1, 1308233432
69, 481, 1892, http://example.com, ::1, 1308233432
487, 49, 1892, http://example.com, ::1, 1308233432
  • a = 位置 y
  • b = 位置 x
  • c = 屏幕分辨率(浏览器)
  • d = 主机
  • e = ip
  • f = 时间戳

我想做的是,例如:

检查它是否在一个 50x50 像素的盒子里,如果是的话,计数 +1。

所以我会有一张像这样的桌子:

y/x |  0 | 50  | 100  | 150
----+----+-----+------+----
50  | 0  |  1  |   2  |   0
100 | 0  |  0  |   1  |   0
150 | 1  |  0  |   0  |   1
200 | 2  |  2  |   3  |   0
etc.

希望有人可以帮助我实现上述目标

他下面的链接正在创建一个热图,http://www.design-code.nl/example/heatmap.php,但是热图是重叠的,所以我想把绿点放在一个被计数的数组中,这些区域在哪里它在 50x50 以内将用其他颜色突出显示。抱歉信息太差

4

5 回答 5

4

好的,我想我已经弄清楚了这个问题是关于什么的(请参阅我对上述问题的评论)。

我这样做的方法是将 X 和 Y 位置除以 50,然后使用该floor()函数从中获取整数值。这将是他们所在的盒子号码。

然后,您可以很容易地将其填充到数组中。

以下代码将生成您需要的数组:

$map = array();
foreach($data as $row) {
    $map[floor($row['x']/50)][floor($row['y']/50)]++;
}

然后您可以将其打印到表格中(行和列标题是单元格编号乘以 50)。

您可能希望事先对数组进行零填充,$map以便在没有任何命中的单元格中获得零,或者您可以在打印时解决此问题;由你决定)

于 2011-06-16T15:10:40.383 回答
0

您想寻找空间填充曲线。sfc 通常用于热图并将 2d 复杂度降低到 1d 复杂度。您想查找 Nick 的希尔伯特曲线空间四叉树博客。

于 2011-06-16T15:10:12.490 回答
0

盒子的坐标是:

$x_coor = floor ($a / 50);
$y_coor = floor ($b / 50);

使用坐标,您可以将它们填满一个 n 维数组

于 2011-06-16T15:05:31.563 回答
0

While this question is poorly worded, I think I understand what you are asking for. Here's what you should do. I am not all that fluent in php so please make sure that you look over the code snippets that I write instead of copy/pasting them.

  1. Find the maximum X and Y values.
  2. Instantiate and initialize a 2D array based on those values divided by 50.

For instance if you wanted Array[X][Y] you would do:

$myArray = array();
for ($x = 0; $x < $maxX / 50; $x++) {
    $myArray[] = array();
    for ($y = 0; $y < $maxY / 50; $y++) {
        $myArray[$x][] = 0;
    }
}

This should instantiate and initialize a 2D array to all 0's just like you need

3) Iterate through your array and for each entry, increment the value of $myArray[$curX/50][$curY/50] by 1:

foreach ($inputArray as $curRow) $myArray[$curRow[b]/50][$curRow[a]/50] += 1;

Again, I'm no pro at php and have really just started working with it, but this should be a good start.

于 2011-06-16T15:04:08.047 回答
0

首先,您需要用 0 填充一个完整的数组:

$result = array();
for($i=0;$i<2000;$i+=50){
    $result[$i] = array();
    for($j=0;$j<2000;$j+=50){
        $result[$i][$j] = 0;
    }
}

其中 2000 是最大屏幕宽度/高度。然后,你计算你的值,$a你的数组在哪里:

foreach($a as $v){
    $result[floor($v[0]/50)*50][floor($v[1]/50)*50]++;
}
于 2011-06-16T15:22:47.157 回答