use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class Collection method basicCheck.
/**
* DB maintenance *********************************************************** ************************************
*/
/*
* Basic integrity check for syncing. True if ok.
*/
public boolean basicCheck() {
// cards without notes
if (mDb.queryScalar("select 1 from cards where nid not in (select id from notes) limit 1") > 0) {
return false;
}
boolean badNotes = mDb.queryScalar("select 1 from notes where id not in (select distinct nid from cards) " + "or mid not in " + Utils.ids2str(getModels().ids()) + " limit 1") > 0;
// notes without cards or models
if (badNotes) {
return false;
}
// invalid ords
for (JSONObject m : getModels().all()) {
// ignore clozes
if (m.getInt("type") != Consts.MODEL_STD) {
continue;
}
// Make a list of valid ords for this model
JSONArray tmpls = m.getJSONArray("tmpls");
boolean badOrd = mDb.queryScalar("select 1 from cards where (ord < 0 or ord >= ?) and nid in ( " + "select id from notes where mid = ?) limit 1", tmpls.length(), m.getLong("id")) > 0;
if (badOrd) {
return false;
}
}
return true;
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class Sched method _lapseConf.
@Override
@NonNull
protected JSONObject _lapseConf(@NonNull Card card) {
DeckConfig conf = _cardConf(card);
// normal deck
if (card.getODid() == 0) {
return conf.getJSONObject("lapse");
}
// dynamic deck; override some attributes, use original deck for others
DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
JSONArray delays = conf.optJSONArray("delays");
if (delays == null) {
delays = oconf.getJSONObject("lapse").getJSONArray("delays");
}
JSONObject dict = new JSONObject();
// original deck
dict.put("minInt", oconf.getJSONObject("lapse").getInt("minInt"));
dict.put("leechFails", oconf.getJSONObject("lapse").getInt("leechFails"));
dict.put("leechAction", oconf.getJSONObject("lapse").getInt("leechAction"));
dict.put("mult", oconf.getJSONObject("lapse").getDouble("mult"));
// overrides
dict.put("delays", delays);
dict.put("resched", conf.getBoolean("resched"));
return dict;
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class Sched method _newConf.
/**
* Tools ******************************************************************** ***************************
*/
@Override
@NonNull
protected JSONObject _newConf(@NonNull Card card) {
DeckConfig conf = _cardConf(card);
// normal deck
if (card.getODid() == 0) {
return conf.getJSONObject("new");
}
// dynamic deck; override some attributes, use original deck for others
DeckConfig oconf = mCol.getDecks().confForDid(card.getODid());
JSONArray delays = conf.optJSONArray("delays");
if (delays == null) {
delays = oconf.getJSONObject("new").getJSONArray("delays");
}
JSONObject dict = new JSONObject();
// original deck
dict.put("ints", oconf.getJSONObject("new").getJSONArray("ints"));
dict.put("initialFactor", oconf.getJSONObject("new").getInt("initialFactor"));
dict.put("bury", oconf.getJSONObject("new").optBoolean("bury", true));
// overrides
dict.put("delays", delays);
dict.put("separate", conf.getBoolean("separate"));
dict.put("order", Consts.NEW_CARDS_DUE);
dict.put("perDay", mReportLimit);
return dict;
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class NoteImporter method initMapping.
public void initMapping() {
List<String> flds = new ArrayList<>();
JSONArray array = mModel.getJSONArray("flds");
for (int i = 0; i < array.length(); i++) {
flds.add(array.getJSONObject(i).getString("name"));
}
// truncate to provided count
flds = flds.subList(0, Math.min(flds.size(), fields()));
// if there's room left, add tags
if (fields() > flds.size()) {
flds.add("_tags");
}
// and if there's still room left, pad
int iterations = fields() - flds.size();
for (int i = 0; i < iterations; i++) {
flds.add(null);
}
mMapping = flds;
}
use of com.ichi2.utils.JSONArray in project AnkiChinaAndroid by ankichinateam.
the class Models method scmhash.
/**
* Schema hash ***********************************************************************************************
*/
/**
* Return a hash of the schema, to see if models are compatible.
*/
public String scmhash(Model m) {
String s = "";
JSONArray flds = m.getJSONArray("flds");
for (int i = 0; i < flds.length(); ++i) {
s += flds.getJSONObject(i).getString("name");
}
JSONArray tmpls = m.getJSONArray("tmpls");
for (int i = 0; i < tmpls.length(); ++i) {
JSONObject t = tmpls.getJSONObject(i);
s += t.getString("name");
}
return Utils.checksum(s);
}
Aggregations