GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4242a5...45ff39 )
by Alex
9s
created

sugarloaf/static/js/index-min.js   B

Complexity

Total Complexity 40
Complexity/F 1.33

Size

Lines of Code 1
Function Count 30

Duplication

Duplicated Lines 1
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 1
loc 1
rs 8.2608
c 1
b 0
f 0
wmc 40
mnd 3
bc 30
fnc 30
bpm 1
cpm 1.3333
noi 8

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like sugarloaf/static/js/index-min.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
function buildCharts(){sugarloaf.ndx=crossfilter(sugarloaf.data.trails),sugarloaf.openDim=sugarloaf.ndx.dimension(function(a){return a.open?"Open":"Closed"}),sugarloaf.openGroup=sugarloaf.openDim.group().reduceCount(function(a){return a.open}),sugarloaf.openChart=dc.rowChart("#chart-row-open"),sugarloaf.openChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.openDim).group(sugarloaf.openGroup).elasticX(!0),sugarloaf.groomedDim=sugarloaf.ndx.dimension(function(a){return a.groomed?"Groomed":"Ungroomed"}),sugarloaf.groomedGroup=sugarloaf.groomedDim.group().reduceCount(function(a){return a.groomed}),sugarloaf.groomedChart=dc.rowChart("#chart-row-groomed"),sugarloaf.groomedChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.groomedDim).group(sugarloaf.groomedGroup).elasticX(!0),sugarloaf.snowmakingDim=sugarloaf.ndx.dimension(function(a){return a.snowmaking?"Snowmaking in progress":"Not snowmaking"}),sugarloaf.snowmakingGroup=sugarloaf.snowmakingDim.group().reduceCount(function(a){return a.snowmaking}),sugarloaf.snowmakingChart=dc.rowChart("#chart-row-snowmaking"),sugarloaf.snowmakingChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.snowmakingDim).group(sugarloaf.snowmakingGroup).elasticX(!0),sugarloaf.difficultyDim=sugarloaf.ndx.dimension(function(a){return a.difficulty}),sugarloaf.difficultyGroup=sugarloaf.difficultyDim.group().reduceCount(function(a){return a.difficulty}),sugarloaf.difficultyChart=dc.rowChart("#chart-row-difficulty"),sugarloaf.difficultyChart.width(WIDTH).height(HEIGHT).margins(MARGINS).dimension(sugarloaf.difficultyDim).group(sugarloaf.difficultyGroup).ordering(function(a){return sugarloaf.difficulty_order[a.key]}).elasticX(!0),sugarloaf.areaDim=sugarloaf.ndx.dimension(function(a){return a.area}),sugarloaf.areaGroup=sugarloaf.areaDim.group().reduceCount(function(a){return a.area}),sugarloaf.areaChart=dc.rowChart("#chart-row-area"),sugarloaf.areaChart.width(WIDTH).height(2*HEIGHT).margins(MARGINS).dimension(sugarloaf.areaDim).group(sugarloaf.areaGroup).elasticX(!0),dc.renderAll()}function summaryToDates(a){var r={};a.conditions.forEach(function(a){void 0===r[a.datetime]&&(r[a.datetime]={}),a.open&&void 0===r[a.datetime][a.difficulty]?r[a.datetime][a.difficulty]=a.trail_count:a.open?r[a.datetime][a.difficulty]+=a.trail_count:void 0===r[a.datetime].closed?r[a.datetime].closed=a.trail_count:r[a.datetime].closed+=a.trail_count});var o=[];return Object.keys(r).forEach(function(a){var t=r[a];t.datetime=sugarloaf.parseDate.parse(a),o.push(t)}),o.sort(function(a,r){return a.datetime<r.datetime?-1:1}),o}function datesToDataset(a){var r=[];return Object.keys(sugarloaf.difficulty_order).forEach(function(o){var t=[];a.forEach(function(a){var r={x:a.datetime};void 0===a[o]?r.y=0:r.y=a[o],t.push(r)}),r.push(t)}),r}function countDate(a){var r=0;for(var o in a)a.hasOwnProperty(o)&&"datetime"!==o&&(r+=a[o]);return r}function buildSummaryChart(a){sugarloaf.dates=summaryToDates(a),width=800-MARGINS.left-MARGINS.right,height=200-MARGINS.top-MARGINS.bottom,sugarloaf.dataset=datesToDataset(sugarloaf.dates),sugarloaf.summary_x=d3.time.scale().range([0,width]).domain(d3.extent(sugarloaf.dates.map(function(a){return a.datetime}))),sugarloaf.summary_y=d3.scale.linear().rangeRound([height,0]).domain([0,d3.max(sugarloaf.dates,function(a){return countDate(a)})]),sugarloaf.summary_stack=d3.layout.stack(),sugarloaf.summary_stack_layers=sugarloaf.summary_stack(sugarloaf.dataset),sugarloaf.summary_area=d3.svg.area().interpolate("cardinal").x(function(a){return sugarloaf.summary_x(a.x)}).y0(function(a){return sugarloaf.summary_y(a.y0)}).y1(function(a){return sugarloaf.summary_y(a.y0+a.y)}),sugarloaf.summary_color=d3.scale.ordinal().range(["#00A64B","#2D2D94","#6D6D6D","#000","#F6AE3B","#FFF"]).domain(["green","blue","black","double-black","terrain-park","closed"]),sugarloaf.summary_xAxis=d3.svg.axis().scale(sugarloaf.summary_x).orient("bottom").ticks(10).tickFormat(d3.time.format("%b %e")),sugarloaf.summary_yAxis=d3.svg.axis().scale(sugarloaf.summary_y).orient("left");var r=d3.select("#chart-summary").append("svg").attr("width",width+MARGINS.left+MARGINS.right).attr("height",height+MARGINS.top+MARGINS.bottom).append("g").attr("transform","translate("+MARGINS.left+","+MARGINS.top+")"),o=r.selectAll(".series").data(sugarloaf.summary_stack_layers).enter().append("path").attr("class","layer").attr("d",function(a){return sugarloaf.summary_area(a)}).style("fill",function(a,r){return sugarloaf.summary_color(Object.keys(sugarloaf.difficulty_order)[r])});r.append("g").attr("class","x axis").attr("transform","translate(0,"+height+")").call(sugarloaf.summary_xAxis),r.append("g").attr("class","y axis").call(sugarloaf.summary_yAxis)}var filename_status="/api/current",filename_summary="/api/summary",WIDTH=300,HEIGHT=200,MARGINS={top:10,left:30,right:20,bottom:20},sugarloaf={};sugarloaf.difficulty_order={beginner:1,intermediate:2,black:3,"double-black":4,"terrain-park":5},sugarloaf.parseDate=d3.time.format("%Y-%m-%dT%H:%M:%S"),d3.json(filename_status,function(a){sugarloaf.data=a,buildCharts()}),d3.json(filename_summary,function(a){sugarloaf.summary=a,buildSummaryChart(sugarloaf.summary)});
1 ignored issue
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable height seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.height.
Loading history...
Bug introduced by
The variable width seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.width.
Loading history...
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The variable o seems to be never used. Consider removing it.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...