小编vei*_*ich的帖子

如何检测用户在iOS上授予麦克风权限?

所以我需要在用户给出(或拒绝)使用麦克风的权限后调用某个函数.

我已经看到了这个:

[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
        if (granted) {
            // Microphone enabled code
            [self someFunction];

        }
        else {
            // Microphone disabled code
        }
 }];
Run Code Online (Sandbox Code Playgroud)

但是,这仅用于检测当前状态.

如果当前状态为"no"并且弹出窗口显示且用户提供权限 - 则不会调用该函数.那是因为在执行此操作的那一刻,权限是"否",直到我们下次运行代码时才会调用该函数.

我想要做的是在用户按下"允许"或"拒绝"后调用一个函数.

谁知道怎么做?

编辑:忘了提它它必须是iOS 7.0兼容的解决方案.

permissions microphone objective-c ios

6
推荐指数
1
解决办法
4583
查看次数

如何将 JSON 模式转换为猫鼬模式

有没有办法采用像下面这样的有效 JSON 模式并将其转换为猫鼬模式?

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "some desc",
  "title": "Product",
  "type": "object",
  "properties": {
    "endpoints": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "poi": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "location_name": {
            "type": "string"
          },
          "distance": {
            "type": "string"
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎非常基本和简单,但我没有在网上找到任何东西。
有很多关于如何获取 JSON 模式的示例,还有很多如何从这样的对象创建 mongoose 模式的示例:
const newSchema = new mongoose.Schema({ name: String });

如果我尝试直接放置 JSON 模式,则会出现错误

node_modules/mongoose/lib/schema.js:674
    throw new TypeError('Undefined type `' + name + '` at `' + …
Run Code Online (Sandbox Code Playgroud)

schema jsonschema mongoose node.js

6
推荐指数
1
解决办法
7288
查看次数

RandomForestRegressor Predict() 从根本上来说很慢吗?

我每秒只能用这个模型进行 2-3 次预测,速度非常慢。使用LinearRegression模型时,我可以轻松实现 40 倍的加速。

我正在使用scikit-learnpython 包和一个非常简单的数据集,其中包含 3 列(dayhourresult),所以基本上有 2 个功能。
dayhour是分类变量。
自然有7类day和24hour类。
训练样本相对较小(cca 5000 个样本)。
训练它只需要一露秒。
但当我继续预测某事时,速度就非常慢。

所以我的问题是:这是基本特征吗?RandomForrestRegressor或者我实际上可以对此做些什么?

from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=100,
                              max_features='auto',
                              oob_score=True,
                              n_jobs=-1,
                              random_state=42,
                              min_samples_leaf=2)
Run Code Online (Sandbox Code Playgroud)

python random-forest scikit-learn

4
推荐指数
1
解决办法
6217
查看次数

Postgres - 将TSTZRANGE拆分为两列

我使用PostgreSQL 9.4我有一个名为表列timerange,并希望写一个SELECT查询将返回的时间范围在两个单独的列time_starttime_end.我试图像数组一样处理它,但它不起作用:

select *, timerange[0] as t_start from schedules;

当前表格:

| id | - - - - - - - - - - -时间范围 - - - - - - - - - - - - - - ----------- |
| ---- | -------------------------------------------- ------------------------------ |
| 1 | ["2017-05-05 19:00:00 + 02","2017-05-05 21:00:00 + 02")|
| 2 | ["2017-05-05 19:00:00 + 02","2017-05-05 21:00:00 + 02")|

所需表格:

| id | -------- -------------- …

sql postgresql datetime date-range

1
推荐指数
1
解决办法
1731
查看次数