最佳实践总结Firebase数据库值

时间:2017-01-28 22:05:03

标签: android firebase firebase-realtime-database

我正在创建一个Firebase Android和Web应用程序,它只是在活动基础上收集模型卡车的重量数据。 所以我列出了卡车及其属性。 参加活动的所有汽车都列在参加货车路径的数据库中,一个条目的样本:

"attendingCars" : {
    "-K_t-PnY49QJP5QXQJ5_" : {
      "carDescription" : "MB SK Sattel mit Kippmulde",
      "carEmptyWeight" : 7.456999778747559,
      "carLoadCnt" : 13,
      "carLoadSummary" : 12.059002876281738,
      "carLoadTotal" : 109.00000762939453,
      "carOwnerAlias" : "Juergen",
      "carThumbHeight" : 120,
      "carThumbImage" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarThumbImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=85c67cc2-8fbf-4196-a5a5-2456f9af8cb4",
      "carThumbWidth" : 160
    }
  }

这些汽车数据还用于向用户显示每辆车收集的所有重量数据的摘要,使用Firebase-UI排序列表的种类。

每个事件都有一个名为“weightDB”的单独路径,其中每个权重都被收集,因此所有个体都被收集。以下部分样本......

"weightDB" : {
    "-Kbam_vawQAITyokJSTi" : {
      "carDbItem" : {
        "description" : "MB SK Sattel mit Kippmulde",
        "emptyWeight" : 7.456999778747559,
        "ownerUserID" : "JE0hF1E3XGOHxLCG2qFLRLOnp693",
        "pictureHeight" : 1944,
        "pictureThumbHeight" : 120,
        "pictureThumbUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarThumbImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=85c67cc2-8fbf-4196-a5a5-2456f9af8cb4",
        "pictureThumbWidth" : 160,
        "pictureUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=241ca576-f618-406e-9e69-f7b655b12672",
        "pictureWidth" : 2592
      },
      "carDbItemKey" : "-K_t-PnY49QJP5QXQJ5_",
      "freightTypeItem" : {
        "name" : "Frachtgut"
      },
      "freightTypeItemKey" : "manualFreightTypeID-5",
      "loadWeight" : 2.3430004119873047,
      "loggerUserID" : "M9EkACOXX7SVWqRHmqVB2euErO03",
      "ownerAlias" : "Juergen",
      "totalWeight" : 9.800000190734863
    },
    "-KbaqrWbOFotXb2ztu7u" : {
      "carDbItem" : {
        "description" : "MB SK Sattel mit Kippmulde",
        "emptyWeight" : 7.456999778747559,
        "ownerUserID" : "JE0hF1E3XGOHxLCG2qFLRLOnp693",
        "pictureHeight" : 1944,
        "pictureThumbHeight" : 120,
        "pictureThumbUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarThumbImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=85c67cc2-8fbf-4196-a5a5-2456f9af8cb4",
        "pictureThumbWidth" : 160,
        "pictureUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=241ca576-f618-406e-9e69-f7b655b12672",
        "pictureWidth" : 2592
      },
      "carDbItemKey" : "-K_t-PnY49QJP5QXQJ5_",
      "freightTypeItem" : {
        "name" : "Frachtgut"
      },
      "freightTypeItemKey" : "manualFreightTypeID-5",
      "loadWeight" : 0.3430004119873047,
      "loggerUserID" : "M9EkACOXX7SVWqRHmqVB2euErO03",
      "ownerAlias" : "Juergen",
      "totalWeight" : 7.800000190734863
    },
    "-KbarlMmUQau_JsJFIZ6" : {
      "carDbItem" : {
        "description" : "MB SK Sattel mit Kippmulde",
        "emptyWeight" : 7.456999778747559,
        "ownerUserID" : "JE0hF1E3XGOHxLCG2qFLRLOnp693",
        "pictureHeight" : 1944,
        "pictureThumbHeight" : 120,
        "pictureThumbUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarThumbImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=85c67cc2-8fbf-4196-a5a5-2456f9af8cb4",
        "pictureThumbWidth" : 160,
        "pictureUri" : "https://firebasestorage.googleapis.com/v0/b/freight-weight.appspot.com/o/images%2FcarImage%2FJPEG_20170107_135650_1498993627.jpg?alt=media&token=241ca576-f618-406e-9e69-f7b655b12672",
        "pictureWidth" : 2592
      },
      "carDbItemKey" : "-K_t-PnY49QJP5QXQJ5_",
      "freightTypeItem" : {
        "name" : "Frachtgut"
      },
      "freightTypeItemKey" : "manualFreightTypeID-5",
      "loadWeight" : 0.44300031661987305,
      "loggerUserID" : "M9EkACOXX7SVWqRHmqVB2euErO03",
      "ownerAlias" : "Juergen",
      "totalWeight" : 7.900000095367432
    },

现在显然,我需要总结每辆车的重量值。 现在唯一的方法是在“weightDB”上执行addChildListener,每次添加权重时,我都会重新计算所有汽车的总和。 首先我想我可以在添加weightDB项目时执行此操作,但是当我离线或多个APP同时执行此操作时,这将导致错误数据。 因此,目前每个APP都进行计算并将其写回数据库(仅当它根据参与的汽车/ $ car / carLoadCnt值汇总了比那里更多的重量数据) 我希望在数据库中得到总和,所以我准备好在Web和Android APP中显示它,而不需要查看weightDB本身。

但是我最终得到了很多听众,我必须采用这种做法来+这听起来很愚蠢。

希望有人能指出我更好的方式。

如果我错过了提供任何内容,请告诉我,但我认为使用的数据应该足够了。

现在我专注于Android APP,而Web前端只显示摘要。

由于

0 个答案:

没有答案