2

ビジネス ロジックを Azure レイヤーに実装しようとしていますが、この node.js スタイルのスクリプトを Insert で把握していません。

これで機能するT-SQLがあります

declare @latitude decimal(23,20)
declare @longitude decimal(23,20)
declare @timeStamp datetime

set @latitude = 37.7858340000000012537
set @longitude = -122.4064170000000046911
set @timeStamp = '2012-12-25 02:58:23'

select longitude, latitude, userid
from blah.actions ba
where 
(
    datediff(second, ba.TimeStamp, @timeStamp) < 5 and
    (ba.longitude - 0.0001 <= @longitude and ba.longitude + 0.0001 >= @longitude) and
    (ba.latitude - 0.0001 <= latitude and ba.latitude + 0.0001 >= latitude) 
)

問題は、関数を使用して、挿入時に Azure スクリプト内のテーブル クエリをフィルター処理するにはどうすればよいかということです。

ということで、もう少し作業。関数を使用してフィルター処理する方法を理解しました (ただし、Azure スクリプトをデバッグする方法にはまだ苦労しています)。私の挿入物には次のものがあります。「内部サーバーエラー」が表示されなくなったため、「機能」していますが、結果をログに記録したり表示したりする方法がわかりません(この Azure に関するヒントは大歓迎です)。このアプリケーションでどれだけ多くの作業を行う必要があるかを理解し始めています。

function dateDiff(date1, date2) 
{
    return date1.getTime() - date2.getTime() / 1000;
}

function insert(item, user, request) {

    request.execute();

    var actionsTable = tables.getTable('BlahActions');

    actionsTable.where(function(currentLat, currentLon, currentTime)
    {
        return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
               (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
               (this.TimeStamp == currentTime);
               //(dateDiff(this.TimeStamp, currentTime) <= 5);
    }, item.Latitude, item.Longitude, item.TimeStamp)
    .read(
    {
        success:function(results)
        {
        }
    });
}

上記のスクリプトの問題は、getTime() を使用すると Azure が吐き出すことです。同じ緯度と経度に近く、過去 X 秒以内に発生したすべてのエントリを取得する必要があります (はい、本質的に「バンプ」を再発明しています)。これは私が現在立ち往生しているところです。この部分を通過した場合は更新します。

4

1 に答える 1

0

ここで学んだいくつかの教訓。何よりもまず、ログ ファイルは、モバイル サービスのルートの上部にある「LOGS」...#epicFacePalm と表示されているメニューで表示できます。2 つ目は、XCode IDE 内の一般的なエラー メッセージではなく、実際のエラー メッセージを確認できるようになったことです。

  • where メソッドの述語内の return ステートメントは、単純な比較のみを行う必要があります。別のメソッドを呼び出して、条件ステートメントの戻り値を確認することはできません。
  • もう 1 つの技術的な詳細は、TimeStamp 列を DateTime から double に変更することでした-変換を必要とせずにタイムスタンプの減算を完全に単純化します-簡単です

そうは言っても、私は今これをwhereメソッドに持っています

    actionsTable.where(function(currentLat, currentLon, currentTime)
    {
        return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
            (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
           (currentTime - this.TimeStamp <= 5);
    }, item.Latitude, item.Longitude, item.TimeStamp)

成功のコールバックで結果をフィルタリングする前に結果をフィルタリングする

.read(
{
    success:function(results)
    {            
       for (var i = 0; i < results.length; i++)
       {
            var obj = results[i];

            for(var key in obj)
            {
                if (key === "id" && 
                    distance(obj.Longitude, obj.Latitude, item.Longitude, item.Latitude) < 30)
                {                        
                }
            }
       }
    }
}

構文を明確にするためのすべて

function insert(item, user, request) {
request.execute();

var actionsTable = tables.getTable('blahActions');
console.log("Inserting new action '%j'", item);

actionsTable.where(function(currentLat, currentLon, currentTime)
{
    return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
           (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
           (currentTime - this.TimeStamp <= 5);
}, item.Latitude, item.Longitude, item.TimeStamp)
.read(
{
    success:function(results)
    {            
       for (var i = 0; i < results.length; i++)
       {
            var obj = results[i];

            for(var key in obj)
            {
                if (key === "id" && 
                    distance(obj.Longitude, obj.Latitude, item.Longitude, item.Latitude) < 30)
                {                        
                }
            }
       }
    }
});

}

于 2012-12-31T19:35:26.130 に答える