Skip to content
Snippets Groups Projects
Commit b6256412 authored by srosse's avatar srosse
Browse files

OO-3895: in weekly stats use WW format for smooth ordering

parent 647afa5f
No related branches found
No related tags found
No related merge requests found
...@@ -164,7 +164,7 @@ insert into o_stat_daily (businesspath, resid, day, value) ...@@ -164,7 +164,7 @@ insert into o_stat_daily (businesspath, resid, day, value)
<value> <value>
update o_stat_weekly set value = value + delta.cnt update o_stat_weekly set value = value + delta.cnt
from (select businesspath as tempbusinesspath, from (select businesspath as tempbusinesspath,
(date_part('year', temptable.creationdate) || '-' || date_part('week', temptable.creationdate)) as w, (date_part('year', temptable.creationdate) || '-' || to_char(temptable.creationdate, 'WW')) as w,
count(*) cnt count(*) cnt
from o_stat_temptable as temptable from o_stat_temptable as temptable
group by tempbusinesspath, w) as delta group by tempbusinesspath, w) as delta
...@@ -174,10 +174,10 @@ from (select businesspath as tempbusinesspath, ...@@ -174,10 +174,10 @@ from (select businesspath as tempbusinesspath,
insert into o_stat_weekly (businesspath, resid, week, value) insert into o_stat_weekly (businesspath, resid, week, value)
(select temptable.businesspath, (select temptable.businesspath,
int8(substring(temptable.businesspath from position(':' in temptable.businesspath) + 1 for position(']' in temptable.businesspath) - position(':' in temptable.businesspath) - 1)) as resid, int8(substring(temptable.businesspath from position(':' in temptable.businesspath) + 1 for position(']' in temptable.businesspath) - position(':' in temptable.businesspath) - 1)) as resid,
(date_part('year', temptable.creationdate) || '-' || date_part('week', temptable.creationdate)) as w, (date_part('year', temptable.creationdate) || '-' || to_char(temptable.creationdate, 'WW')) as w,
count(*) as cnt count(*) as cnt
from o_stat_temptable as temptable from o_stat_temptable as temptable
left join o_stat_weekly old on (temptable.businesspath=old.businesspath and (date_part('year', temptable.creationdate) || '-' || date_part('week', temptable.creationdate))=old.week) left join o_stat_weekly old on (temptable.businesspath=old.businesspath and (date_part('year', temptable.creationdate) || '-' || to_char(temptable.creationdate, 'WW'))=old.week)
where temptable.businesspath != '' and old.businesspath is null where temptable.businesspath != '' and old.businesspath is null
group by temptable.businesspath, w); group by temptable.businesspath, w);
</value> </value>
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.upgrade;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.persistence.DB;
import org.olat.course.statistic.StatisticUpdateManager;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 20 févr. 2019<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class OLATUpgrade_12_5_17 extends OLATUpgrade {
private static final String VERSION = "OLAT_12.5.17";
private static final String UPDATE_COURSE_STATS = "UPDATE COURSE STATS";
@Autowired
private DB dbInstance;
public OLATUpgrade_12_5_17() {
super();
}
@Override
public String getVersion() {
return VERSION;
}
@Override
public boolean doPreSystemInitUpgrade(UpgradeManager upgradeManager) {
return false;
}
@Override
public boolean doPostSystemInitUpgrade(UpgradeManager upgradeManager) {
UpgradeHistoryData uhd = upgradeManager.getUpgradesHistory(VERSION);
if (uhd == null) {
// has never been called, initialize
uhd = new UpgradeHistoryData();
} else if (uhd.isInstallationComplete()) {
return false;
}
boolean allOk = true;
allOk &= updateCourseStatistics(upgradeManager, uhd);
uhd.setInstallationComplete(allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION);
if(allOk) {
log.audit("Finished OLATUpgrade_12_5_17 successfully!");
} else {
log.audit("OLATUpgrade_12_5_17 not finished, try to restart OpenOLAT!");
}
return allOk;
}
private boolean updateCourseStatistics(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
boolean allOk = true;
if (!uhd.getBooleanDataValue(UPDATE_COURSE_STATS)) {
if(dbInstance.isPostgreSQL()) {
StatisticUpdateManager statisticManager = (StatisticUpdateManager) CoreSpringFactory.getBean("org.olat.course.statistic.StatisticUpdateManager");
if(statisticManager != null) {
statisticManager.updateStatistics(true, new Runnable() {
@Override
public void run() {
//
}
});
}
}
uhd.setBooleanDataValue(UPDATE_COURSE_STATS, allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return allOk;
}
}
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<bean id="upgrade_12_4_0" class="org.olat.upgrade.OLATUpgrade_12_4_0"/> <bean id="upgrade_12_4_0" class="org.olat.upgrade.OLATUpgrade_12_4_0"/>
<bean id="upgrade_12_4_1" class="org.olat.upgrade.OLATUpgrade_12_4_1"/> <bean id="upgrade_12_4_1" class="org.olat.upgrade.OLATUpgrade_12_4_1"/>
<bean id="upgrade_12_5_3" class="org.olat.upgrade.OLATUpgrade_12_5_3"/> <bean id="upgrade_12_5_3" class="org.olat.upgrade.OLATUpgrade_12_5_3"/>
<bean id="upgrade_12_5_17" class="org.olat.upgrade.OLATUpgrade_12_5_17"/>
</list> </list>
</property> </property>
</bean> </bean>
......
...@@ -44,8 +44,7 @@ import org.olat.test.JunitTestHelper; ...@@ -44,8 +44,7 @@ import org.olat.test.JunitTestHelper;
*/ */
public class WeeklyStatisticUpdateManagerTest extends AbstractStatisticUpdateManagerTest { public class WeeklyStatisticUpdateManagerTest extends AbstractStatisticUpdateManagerTest {
private final SimpleDateFormat weeklyFormat = new SimpleDateFormat("yyyy-w"); private final SimpleDateFormat weeklyFormat = new SimpleDateFormat("yyyy-ww");
private final SimpleDateFormat weeklyMySQLFormat = new SimpleDateFormat("yyyy-ww");
private final WeeklyStatisticManager weeklyStatisticManager = new WeeklyStatisticManager(); private final WeeklyStatisticManager weeklyStatisticManager = new WeeklyStatisticManager();
...@@ -128,10 +127,6 @@ public class WeeklyStatisticUpdateManagerTest extends AbstractStatisticUpdateMan ...@@ -128,10 +127,6 @@ public class WeeklyStatisticUpdateManagerTest extends AbstractStatisticUpdateMan
cal.set(Calendar.SECOND, 0); cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.MILLISECOND, 0);
if(dbInstance.isMySQL()) {
weeklyMySQLFormat.setCalendar(cal);
return weeklyMySQLFormat.format(cal.getTime());
}
weeklyFormat.setCalendar(cal); weeklyFormat.setCalendar(cal);
return weeklyFormat.format(cal.getTime()); return weeklyFormat.format(cal.getTime());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment