<commit_before>import groovy.text.SimpleTemplateEngine
import java.text.DateFormat
import java.text.SimpleDateFormat

class HutsTagLib {
    def showBooking = {attrs, body ->
        if (attrs.userId) {
            def b = Booking.get(attrs.bookingId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (p.admin || b.hut.owner == p || b.contact == p)) {
                out << body()
            }
        }
    }

    def showBookingDate = {attrs, body ->
        if (attrs.userId) {
            def b = Booking.get(attrs.bookingId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (!(p.admin || b.hut.owner == p || b.contact == p))) {
                out << body()
            }
        }
    }

    def hasHut = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            if (p.owns && p.owns.size() > 0) {
                out << body()
            }
        }
    }

    def hasBooking = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            def bookings = Booking.findAllByContact(p)

            if (bookings && bookings.size() > 0) {
                out << body()
            }
        }
    }

    def manageHut = {attrs, body ->
        if (attrs.userId) {
            def h = Hut.get(attrs.hutId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (p.admin || h.owner == p)) {
                out << body()
            }
        }
    }

    def isAdmin = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            if (p && p.admin) {
                out << body()
            }
        }
    }

    def monthView = {attrs ->

        def hut = Hut.get(attrs.hutId)

        def count = 3
        if (attrs.monthcount) {
            count = new Integer(attrs.monthcount)
        }

        Calendar cal = Calendar.getInstance()
        cal.setFirstDayOfWeek(Calendar.MONDAY)

        DateFormat monthYear = new SimpleDateFormat("MMM yyyy");

        out << "<table><tr valign='top'>"

        1.upto(count) {c ->

            out << "<td><table class='datetable'><tr><th colspan='8'>"

            out << monthYear.format(cal.getTime());

            out << "</th></tr>"

            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1)

            def startWeek = cal.get(Calendar.WEEK_OF_YEAR)

            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, 1)

            cal.add(Calendar.DAY_OF_YEAR, -1)

            def endWeek = cal.get(Calendar.WEEK_OF_YEAR)

            def maxWeekOfYear = 54

            if (endWeek < startWeek) {
                // December - we rolled round
                cal.add(Calendar.WEEK_OF_YEAR, -1)

                maxWeekOfYear = cal.get(Calendar.WEEK_OF_YEAR)

                endWeek = maxWeekOfYear + 1
            }

            def lastDayOfMonth = cal.get(Calendar.DAY_OF_WEEK)

            cal.set(Calendar.WEEK_OF_YEAR, startWeek)

            cal.set(Calendar.DAY_OF_MONTH, 1)

            def dow = cal.get(Calendar.DAY_OF_WEEK)

            if (dow < Calendar.MONDAY) {
                dow = dow + 7
            }
            dow = dow - (Calendar.MONDAY + 1)

            def prefix = 7 - dow


            def suffix = 7 - (lastDayOfMonth - 1)

            if (suffix == 7) {
                suffix = 0
            }

            out << "<tr><th>&nbsp;</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></th>"

            def lastDate = 0

            for (week in startWeek..endWeek) {
                out << "<tr>"<commit_msg>Close row properly<commit_after>import groovy.text.SimpleTemplateEngine
import java.text.DateFormat
import java.text.SimpleDateFormat

class HutsTagLib {
    def showBooking = {attrs, body ->
        if (attrs.userId) {
            def b = Booking.get(attrs.bookingId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (p.admin || b.hut.owner == p || b.contact == p)) {
                out << body()
            }
        }
    }

    def showBookingDate = {attrs, body ->
        if (attrs.userId) {
            def b = Booking.get(attrs.bookingId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (!(p.admin || b.hut.owner == p || b.contact == p))) {
                out << body()
            }
        }
    }

    def hasHut = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            if (p.owns && p.owns.size() > 0) {
                out << body()
            }
        }
    }

    def hasBooking = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            def bookings = Booking.findAllByContact(p)

            if (bookings && bookings.size() > 0) {
                out << body()
            }
        }
    }

    def manageHut = {attrs, body ->
        if (attrs.userId) {
            def h = Hut.get(attrs.hutId)

            def p = Person.findByUserId(attrs.userId)

            if (p && (p.admin || h.owner == p)) {
                out << body()
            }
        }
    }

    def isAdmin = {attrs, body ->
        if (attrs.userId) {
            def p = Person.findByUserId(attrs.userId)

            if (p && p.admin) {
                out << body()
            }
        }
    }

    def monthView = {attrs ->

        def hut = Hut.get(attrs.hutId)

        def count = 3
        if (attrs.monthcount) {
            count = new Integer(attrs.monthcount)
        }

        Calendar cal = Calendar.getInstance()
        cal.setFirstDayOfWeek(Calendar.MONDAY)

        DateFormat monthYear = new SimpleDateFormat("MMM yyyy");

        out << "<table><tr valign='top'>"

        1.upto(count) {c ->

            out << "<td><table class='datetable'><tr><th colspan='8'>"

            out << monthYear.format(cal.getTime());

            out << "</th></tr>"

            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1)

            def startWeek = cal.get(Calendar.WEEK_OF_YEAR)

            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, 1)

            cal.add(Calendar.DAY_OF_YEAR, -1)

            def endWeek = cal.get(Calendar.WEEK_OF_YEAR)

            def maxWeekOfYear = 54

            if (endWeek < startWeek) {
                // December - we rolled round
                cal.add(Calendar.WEEK_OF_YEAR, -1)

                maxWeekOfYear = cal.get(Calendar.WEEK_OF_YEAR)

                endWeek = maxWeekOfYear + 1
            }

            def lastDayOfMonth = cal.get(Calendar.DAY_OF_WEEK)

            cal.set(Calendar.WEEK_OF_YEAR, startWeek)

            cal.set(Calendar.DAY_OF_MONTH, 1)

            def dow = cal.get(Calendar.DAY_OF_WEEK)

            if (dow < Calendar.MONDAY) {
                dow = dow + 7
            }
            dow = dow - (Calendar.MONDAY + 1)

            def prefix = 7 - dow


            def suffix = 7 - (lastDayOfMonth - 1)

            if (suffix == 7) {
                suffix = 0
            }

            out << "<tr><th>&nbsp;</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>"

            def lastDate = 0

            for (week in startWeek..endWeek) {
                out << "<tr>"
{'fraction_non_alphanumeric': 0.13530770275777748, 'fraction_numerical': 0.005977448716207037, 'mean_word_length': 1.4177339901477832, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776580', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2298, 'n_words': 459}